-
Notifications
You must be signed in to change notification settings - Fork 98
SetAttribute on Missing Attribute Path Silently Fails Without Update #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Definitely a bug. The original design for There are some cases in which this is non-trivial. For example (via @paddycarver), consider a case in which a SetAttribute(ctx, tftypes.NewAttributePath().WithAttributeName("list_of_things").WithElementKeyInt(12), "value") In this case, the practitioner probably does not expect that elements 5-11 should be inserted into the list in order that element 12 be added. This call should therefore error. There are likely other edge cases to discuss below. This suggests to me that
Either of these steps can return an error. |
My proposal (hopefully matching everyone else's thoughts) is the following behaviors for
These should probably be explicitly documented on the method. 😄 |
To capture context verbalised elsewhere, I think we have three potential approaches here: Strict SuccessWe always make this succeed (as long as the path is valid for the schema), creating whatever values we need to to set the attribute that was specified. If that means inserting extra items in lists, so be it. Strict FailureWe always make this fail when the value being pointed at by the path doesn't exist yet. When modifying a list, set, or map the entire list, set, or map must be replaced, it cannot be modified piecemeal. Least SurpriseWe do our best to do what a user would expect: create the value when it doesn't exist at the specified path, but in the case of lists, we throw an error instead of creating empty values. The only values that it's valid to create are: any element of a map, any element of a set, and only the next element in a list. |
I believe Brian's proposal matches least surprise, and I think that's what I'm leaning towards. I haven't thought of any other edge cases besides adding elements to a list. |
Another edge case is if the parent path (recursive) beyond just the List/Set/Map is missing. For example with: tftypes.NewAttributePath().WithAttributeName("this").WithAttributeName("list_attr")
// or nested further...
tftypes.NewAttributePath().WithAttributeName("this").WithAttributeName("list_attr").WithElementKeyInt(0) And the |
Hmm, I dunno if I agree on that being a surprising edge case. I think as a provider developer, I would expect Otherwise, I think we're back at lists, sets, objects, and maps pretty much always need to be set as atomic attributes, instead of being able to update specific elements/attributes in them. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Module version
Description
Given a schema like:
And example "empty" State assembly:
With the call:
Expected Behavior
(Plan).SetAttribute()
and(State).SetAttribute()
should provide feedback about not updating the state properly or the behavior is documented in the Go documentation for those methods.Actual Behavior
Calling
(State).SetAttribute()
will silently fail, but the state will not be updated. This is because the transform function has no paths to match in this scenario and thereforep.Equal(path)
will never match.This was found while initially investigating how import support could work, but the same implications could apply to other places where new attribute paths are being introduced, such as
(DataSource).Read()
methods not callingSet()
first or potentially adding elements to an existing attribute (although I have not verified either of these myself).The text was updated successfully, but these errors were encountered: