-
Notifications
You must be signed in to change notification settings - Fork 96
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
Panic for unset types.Number #89
Comments
Hi @lirossarvet 👋 Thank you so much for filing this detailed bug report. This is certainly not expected behavior! We have a fix for this that will be proposed soon and we will let you know when this is resolved. In the meantime, using type MyResourceData struct {
MyAttribute *big.Float `tfsdk:my_attribute"
} |
Reference: hashicorp/terraform-plugin-framework#89 This matches the consistency of other pointer types in the `valueFromNumber` function and can prevent unexpected panics.
…114) Reference: hashicorp/terraform-plugin-framework#89 This matches the consistency of other pointer types in the `valueFromNumber` function and can prevent unexpected panics.
Reference: #89 Reference: hashicorp/terraform-plugin-go#114 This change will ensure that if the `Number` `Value` pointer is `nil`, that the returned value is an untyped `nil`, rather than a `*big.Float` typed `nil`. The upstream `(tftypes.Value).IsNull()` method can only detect untyped `nil` for values. A related fix for `tftypes.NewValue()` to convert a `*big.Float` `nil` value into an untyped `nil` has also been merged upstream to fix this in depth. Previously, this new test case would pass: ```go "value-nil": { input: Number{Value: nil}, expectation: (*big.Float)(nil), }, ``` Now it appropriately expects: ```go "value-nil": { input: Number{Value: nil}, expectation: nil, }, ```
Reference: #89 Reference: hashicorp/terraform-plugin-go#114 This change will ensure that if the `Number` `Value` pointer is `nil`, that the returned value is an untyped `nil`, rather than a `*big.Float` typed `nil`. The upstream `(tftypes.Value).IsNull()` method can only detect untyped `nil` for values. A related fix for `tftypes.NewValue()` to convert a `*big.Float` `nil` value into an untyped `nil` has also been merged upstream to fix this in depth. Previously, this new test case would pass: ```go "value-nil": { input: Number{Value: nil}, expectation: (*big.Float)(nil), }, ``` Now it appropriately expects: ```go "value-nil": { input: Number{Value: nil}, expectation: nil, }, ```
The fix for this has been merged and will be part of the next terraform-plugin-framework release, either v0.4.3 (if shipped) or v0.5.0, in the coming weeks. 🎉 |
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
Relevant provider source code
https://gist.github.com/lirossarvet/8be0ce992f2ac44edf60ff28d31681b0
This is the relevant chunk, I think, or at least enough. The whole resource is in the gist, though.
API Client struct
Terraform Configuration Files
Debug Output
Panic output is in the gist posted above. I can share the trace logs if needed.
Expected Behavior
An unset Optional
types.Number
attribute would not cause a panic and would instead not set the value in state or ignore it.Actual Behavior
Panic! (in the terraform provider)
Steps to Reproduce
types.NumberType
andOptional: true
State.Set
with something like:References
The text was updated successfully, but these errors were encountered: