Skip validation of a values missing in config#259
Skip validation of a values missing in config#259gzigzigzeo wants to merge 4 commits intohashicorp:mainfrom
Conversation
|
Similar crash reported in hashicorp/terraform-provider-awscc#382. terraform-plugin-framework/tfsdk/state.go Lines 80 to 100 in 5f18d80 |
|
@ewbankkit Thanks for pointing this out, provided failed test and fixed it as well. |
|
Hi @gzigzigzeo 👋 Thanks for submitting this and sorry you ran into trouble here. In general, the preference for this framework should be performing attribute validation in all cases. This allows provider developers to check against My recommendation here would be to revert the general validation logic and instead perform a if in == nil {
return diags
}
if !in.Type().Equal(tftypes.Number) { // ...Please reach out if you have any questions (although it may take a week for a next response). |
|
Hey, @bflad! Thank you for the clarification! In fact, reverting of this logic was my initial thought, and performing it in float64.go and int64.go fixed the issue. At that moment, I thought that it was a bit implicit and does not guarantee a custom user validations from failing. I now see why your approach is better and framework should not guarantee anything here. I am going to fix my implementation accordingly, add a counterpart tests for other built-in types and push it to this PR. Thanks again. |
|
@bflad Done! |
bflad
left a comment
There was a problem hiding this comment.
Thanks for the updates, @gzigzigzeo. Since I didn't want to break your main branch by updating it, this will get pulled in as a separate commit. I will also fix the Set validation (#261) as part of pulling this in.
| "Computed-Computed-object": { | ||
| config: Config{ | ||
| Raw: tftypes.NewValue(tftypes.Object{ | ||
| AttributeTypes: map[string]tftypes.Type{ | ||
| "name": tftypes.String, | ||
| }, | ||
| }, map[string]tftypes.Value{ | ||
| "name": tftypes.NewValue(tftypes.String, "namevalue"), | ||
| }), | ||
| Schema: Schema{ | ||
| Attributes: map[string]Attribute{ | ||
| "name": { | ||
| Type: testtypes.StringTypeWithValidateWarning{}, | ||
| Required: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| target: new(testtypes.String), | ||
| expected: &testtypes.String{String: types.String{Value: "namevalue"}, CreatedBy: testtypes.StringTypeWithValidateWarning{}}, | ||
| expectedDiags: diag.Diagnostics{testtypes.TestWarningDiagnostic(tftypes.NewAttributePath().WithAttributeName("name"))}, | ||
| }, |
There was a problem hiding this comment.
This test looks identical to the one above, so will remove on merge.
| // If found, convert this value to an unknown value. | ||
| // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/186 | ||
|
|
||
| if attrTypeWithValidate, ok := attrType.(attr.TypeWithValidate); ok { |
There was a problem hiding this comment.
Similar to Config, this logic should not be changed, will fix on merge.
| expected: testtypes.String{String: types.String{Value: "value"}, CreatedBy: testtypes.StringTypeWithValidateWarning{}}, | ||
| expectedDiags: diag.Diagnostics{testtypes.TestWarningDiagnostic(tftypes.NewAttributePath().WithAttributeName("test"))}, | ||
| }, | ||
| "AttrTypeInt64WithValidateError-nested-missing-in-config": { |
There was a problem hiding this comment.
Will ensure there is a covering test in plan as well.
|
Merged as c584343 |
This fork was created because of this PR hashicorp/terraform-plugin-framework#259 It was upstreamed as part of the 0.6.1 release: https://github.com/hashicorp/terraform-plugin-framework/releases/tag/v0.6.1 We can now remove the replace directive
|
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. |
Problem
I have the following schema:
And the following config:
"spec"is the base object,"options"is the child computed object, and"max_sessions"is the bottommost Int64 value, which, in turn, is also computed.optionsmight either be missing in my configuration at all, set partially or set completely, includingmax_sessionsattribute.When
optionssection is missing in the configuration completely, Terraform crashes:Solution
That happens because Terraform Framework tries to validate the type of
spec.options.max_sessionsconfig value, which is missing in the config, hence, can't have a type to validate. It must be skipped.