Conversation
…returns cannot mutate underlying data Reference: #556 Reference: #582 This will ensure that the `Attributes()`, `AttributeTypes()`, and `Elements()` methods return a copy of the underlying map or slice of data, rather than a direct reference to the map or slice. This also prevents `Object`-based plan modification from returning a panic since the updated `Object` `Attributes()` implementation will return an empty map instead of a `nil` map. Provider implementations should always rely on `IsNull()` and `IsUnknown()` for verifying whether types are known, rather than a nil comparison. This is considered a bug fix for the intended behavior of these type implementations rather than a breaking change as it standardizes type handling expectations. New unit testing failures before code updates: ``` --- FAIL: TestMapValueElements_immutable (0.00s) /Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/types/basetypes/map_test.go:604: unexpected Elements mutation --- FAIL: TestNestedAttributeObjectPlanModify (0.00s) --- FAIL: TestNestedAttributeObjectPlanModify/response-planvalue-unknown-to-known-nested (0.00s) panic: assignment to entry in nil map [recovered] panic: assignment to entry in nil map goroutine 35 [running]: testing.tRunner.func1.2({0x1010f0180, 0x10115b648}) /opt/homebrew/Cellar/go/1.19.4/libexec/src/testing/testing.go:1396 +0x1c8 testing.tRunner.func1() /opt/homebrew/Cellar/go/1.19.4/libexec/src/testing/testing.go:1399 +0x378 panic({0x1010f0180, 0x10115b648}) /opt/homebrew/Cellar/go/1.19.4/libexec/src/runtime/panic.go:884 +0x204 github.com/hashicorp/terraform-plugin-framework/internal/fwserver.NestedAttributeObjectPlanModify({_, _}, {_, _}, {{{0x1400010d190, 0x1, 0x1}}, {0x1, {0x1400010d1b0, 0x1, ...}}, ...}, ...) /Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/internal/fwserver/attribute_plan_modification.go:1748 +0x510 ```
bendbennett
approved these changes
Dec 19, 2022
| }, | ||
| }, | ||
| }, | ||
| // PlanModifiers: []planmodifier.Object{ |
Contributor
There was a problem hiding this comment.
Should the commented code be removed?
Contributor
Author
There was a problem hiding this comment.
Yes it should, thanks.
bflad
commented
Dec 19, 2022
|
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #556
Closes #582
This will ensure that the
Attributes(),AttributeTypes(), andElements()methods return a copy of the underlying map or slice of data, rather than a direct reference to the map or slice. This also preventsObject-based plan modification from returning a panic since the updatedObjectAttributes()implementation will return an empty map instead of anilmap. Provider implementations should always rely onIsNull()andIsUnknown()for verifying whether types are known, rather than a nil comparison. This is considered a bug fix for the intended behavior of these type implementations rather than a breaking change as it standardizes type handling expectations.New unit testing failures before code updates: