-
Notifications
You must be signed in to change notification settings - Fork 99
internal/fwserver: Ensure Attribute and Block Plan Modification Returns Custom Value Type Implementations When Using Custom Type NestedAttributeObject/NestedBlockObject #823
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
Conversation
austinvalle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm 🎸
bflad
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! One minor testing thing I noticed, otherwise looks good to me 🚀
| basetypes.ObjectType{ | ||
| AttrTypes: map[string]attr.Type{ | ||
| "nested_attr": types.StringType, | ||
| }, | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I might be being dense, should this be c.ObjectValue.Type(ctx) so it matches up with how the type was created?
Similarly with the other custom types below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I've misunderstood, but I don't think we can use the return value of c.ObjectValue.Type(ctx) as the type is attr.Type and NestedObjectCustomType expects the embedded type to be basetypes.ObjectType:
func (c NestedObjectCustomValue) Type(ctx context.Context) attr.Type {
return NestedObjectCustomType{
c.ObjectValue.Type(ctx), // wrong type, expects `basetypes.ObjectType`, gets `attr.Type`
}
}However, we could use a call to obtain the attributes for the embedded basetypes.ObjectType, for instance:
func (c NestedObjectCustomValue) Type(ctx context.Context) attr.Type {
return NestedObjectCustomType{
basetypes.ObjectType{
AttrTypes: c.AttributeTypes(ctx),
},
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, you are correct -- I was just surprised by the hardcoded attribute names/types in there.
If this works:
func (c NestedObjectCustomValue) Type(ctx context.Context) attr.Type {
return NestedObjectCustomType{
basetypes.ObjectType{
AttrTypes: c.AttributeTypes(ctx),
},
}
}
I'd highly suggest it, so anyone can implement test schemas without hardcoded schema implementation details. 👍
|
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. |
Closes: #767
Closes: #821
Reference: #768
This PR addresses diagnostic errors arising from using a
CustomTypeassociated with aNestedObjectwithin aListNestedAttribute,ListNestedBlock,MapNestedAttribute,SetNestedAttributeorSetNestedBlock. The diagnostic error generated isInvalid ... Element Type. Further details can be found in #821 and #767.Previously, before logic updates:
=== NAME TestAttributeModifyPlan/attribute-map-nested-nested-custom-nested-object attribute_plan_modification_test.go:3285: Unexpected response (-wanted, +got): fwserver.ModifyAttributePlanResponse{ AttributePlan: s`{"outer":{"nested_map_nested_attribute":{"inner":{"nested_attr":`..., - Diagnostics: nil, + Diagnostics: diag.Diagnostics{ + diag.ErrorDiagnostic{ + detail: "While creating a Map value, an invalid element was detected. A M"..., + summary: "Invalid Map Element Type", + }, + diag.ErrorDiagnostic{ + detail: "While creating a Map value, an invalid element was detected. A M"..., + summary: "Invalid Map Element Type", + }, + }, RequiresReplace: s"[]", Private: nil, } === NAME TestAttributeModifyPlan/attribute-map-nested-custom-nested-object attribute_plan_modification_test.go:3285: Unexpected response (-wanted, +got): fwserver.ModifyAttributePlanResponse{ AttributePlan: s`{"testkey":{"nested_attr":"testvalue"}}`, - Diagnostics: nil, + Diagnostics: diag.Diagnostics{ + diag.ErrorDiagnostic{ + detail: "While creating a Map value, an invalid element was detected. A M"..., + summary: "Invalid Map Element Type", + }, + }, RequiresReplace: s"[]", Private: nil, } === NAME TestAttributeModifyPlan/attribute-set-nested-custom-nested-object attribute_plan_modification_test.go:3285: Unexpected response (-wanted, +got): fwserver.ModifyAttributePlanResponse{ AttributePlan: s`[{"nested_attr":"testvalue"}]`, - Diagnostics: nil, + Diagnostics: diag.Diagnostics{ + diag.ErrorDiagnostic{ + detail: "While creating a Set value, an invalid element was detected. A S"..., + summary: "Invalid Set Element Type", + }, + }, RequiresReplace: s"[]", Private: nil, } === NAME TestAttributeModifyPlan/attribute-list-nested-nested-custom-nested-object attribute_plan_modification_test.go:3285: Unexpected response (-wanted, +got): fwserver.ModifyAttributePlanResponse{ AttributePlan: s`[{"nested_list_nested_attribute":[{"nested_attr":"testvalue"}]}]`, - Diagnostics: nil, + Diagnostics: diag.Diagnostics{ + diag.ErrorDiagnostic{ + detail: "While creating a List value, an invalid element was detected. A "..., + summary: "Invalid List Element Type", + }, + diag.ErrorDiagnostic{ + detail: "While creating a List value, an invalid element was detected. A "..., + summary: "Invalid List Element Type", + }, + }, RequiresReplace: s"[]", Private: nil, } === NAME TestAttributeModifyPlan/attribute-list-nested-custom-nested-object attribute_plan_modification_test.go:3285: Unexpected response (-wanted, +got): fwserver.ModifyAttributePlanResponse{ AttributePlan: s`[{"nested_attr":"testvalue"}]`, - Diagnostics: nil, + Diagnostics: diag.Diagnostics{ + diag.ErrorDiagnostic{ + detail: "While creating a List value, an invalid element was detected. A "..., + summary: "Invalid List Element Type", + }, + }, RequiresReplace: s"[]", Private: nil, } === NAME TestAttributeModifyPlan/attribute-set-nested-nested-custom-nested-object attribute_plan_modification_test.go:3285: Unexpected response (-wanted, +got): fwserver.ModifyAttributePlanResponse{ AttributePlan: s`[{"nested_set_nested_attribute":[{"nested_attr":"testvalue"}]}]`, - Diagnostics: nil, + Diagnostics: diag.Diagnostics{ + diag.ErrorDiagnostic{ + detail: "While creating a Set value, an invalid element was detected. A S"..., + summary: "Invalid Set Element Type", + }, + diag.ErrorDiagnostic{ + detail: "While creating a Set value, an invalid element was detected. A S"..., + summary: "Invalid Set Element Type", + }, + }, RequiresReplace: s"[]", Private: nil, }=== NAME TestBlockModifyPlan/block-set-nested-nested-custom-nested-object block_plan_modification_test.go:4040: Error: Invalid Set Element Type While creating a Set value, an invalid element was detected. A Set must use the single, given element type. This is always an issue with the provider and should be reported to the provider developers. Set Element Type: NestedObjectCustomType Set Index (0) Element Type: types.ObjectType["nested_attr":basetypes.StringType] === NAME TestBlockModifyPlan/block-set-nested-custom-nested-object block_plan_modification_test.go:4040: Error: Invalid Set Element Type While creating a Set value, an invalid element was detected. A Set must use the single, given element type. This is always an issue with the provider and should be reported to the provider developers. Set Element Type: NestedObjectCustomType Set Index (0) Element Type: types.ObjectType["nested_attr":basetypes.StringType] === NAME TestBlockModifyPlan/block-list-nested-nested-custom-nested-object block_plan_modification_test.go:4040: Error: Invalid List Element Type While creating a List value, an invalid element was detected. A List must use the single, given element type. This is always an issue with the provider and should be reported to the provider developers. List Element Type: NestedObjectCustomType List Index (0) Element Type: types.ObjectType["nested_attr":basetypes.StringType] block_plan_modification_test.go:4040: Error: Invalid List Element Type While creating a List value, an invalid element was detected. A List must use the single, given element type. This is always an issue with the provider and should be reported to the provider developers. List Element Type: ListNestedObjectCustomType List Index (0) Element Type: types.ObjectType["nested_list_nested":types.ListType[NestedObjectCustomType]] block_plan_modification_test.go:4042: Unexpected response (+wanted, -got): fwserver.ModifyAttributePlanResponse{ AttributePlan: s`[{"nested_list_nested":[{"nested_attr":"testvalue"}]}]`, - Diagnostics: nil, + Diagnostics: diag.Diagnostics{ + diag.ErrorDiagnostic{ + detail: "While creating a List value, an invalid element was detected. A "..., + summary: "Invalid List Element Type", + }, + diag.ErrorDiagnostic{ + detail: "While creating a List value, an invalid element was detected. A "..., + summary: "Invalid List Element Type", + }, + }, RequiresReplace: s"[]", Private: nil, } === NAME TestBlockModifyPlan/block-set-nested-custom-nested-object block_plan_modification_test.go:4042: Unexpected response (+wanted, -got): fwserver.ModifyAttributePlanResponse{ AttributePlan: s`[{"nested_attr":"testvalue"}]`, - Diagnostics: nil, + Diagnostics: diag.Diagnostics{ + diag.ErrorDiagnostic{ + detail: "While creating a Set value, an invalid element was detected. A S"..., + summary: "Invalid Set Element Type", + }, + }, RequiresReplace: s"[]", Private: nil, } === NAME TestBlockModifyPlan/block-set-nested-nested-custom-nested-object block_plan_modification_test.go:4040: Error: Invalid Set Element Type While creating a Set value, an invalid element was detected. A Set must use the single, given element type. This is always an issue with the provider and should be reported to the provider developers. Set Element Type: SetNestedObjectCustomType Set Index (0) Element Type: types.ObjectType["nested_set_nested":types.SetType[NestedObjectCustomType]] === NAME TestBlockModifyPlan/block-set-nested-nested-custom-nested-object block_plan_modification_test.go:4042: Unexpected response (+wanted, -got): fwserver.ModifyAttributePlanResponse{ AttributePlan: s`[{"nested_set_nested":[{"nested_attr":"testvalue"}]}]`, - Diagnostics: nil, + Diagnostics: diag.Diagnostics{ + diag.ErrorDiagnostic{ + detail: "While creating a Set value, an invalid element was detected. A S"..., + summary: "Invalid Set Element Type", + }, + diag.ErrorDiagnostic{ + detail: "While creating a Set value, an invalid element was detected. A S"..., + summary: "Invalid Set Element Type", + }, + }, RequiresReplace: s"[]", Private: nil, } === NAME TestBlockModifyPlan/block-list-nested-custom-nested-object block_plan_modification_test.go:4040: Error: Invalid List Element Type While creating a List value, an invalid element was detected. A List must use the single, given element type. This is always an issue with the provider and should be reported to the provider developers. List Element Type: NestedObjectCustomType List Index (0) Element Type: types.ObjectType["nested_attr":basetypes.StringType] block_plan_modification_test.go:4042: Unexpected response (+wanted, -got): fwserver.ModifyAttributePlanResponse{ AttributePlan: s`[{"nested_attr":"testvalue"}]`, - Diagnostics: nil, + Diagnostics: diag.Diagnostics{ + diag.ErrorDiagnostic{ + detail: "While creating a List value, an invalid element was detected. A "..., + summary: "Invalid List Element Type", + }, + }, RequiresReplace: s"[]", Private: nil, }