Skip to content

tfsdk: (Plan).SetAttribute() and (State).SetAttribute() Reflection Missing Attribute Path #128

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

Closed
bflad opened this issue Sep 3, 2021 · 1 comment · Fixed by #133
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@bflad
Copy link
Contributor

bflad commented Sep 3, 2021

Module version

Pre v0.3.0 with validation support

Relevant framework source code

// tfsdk/plan.go
func (p *Plan) SetAttribute(ctx context.Context, path *tftypes.AttributePath, val interface{}) []*tfprotov6.Diagnostic {
  // ...
  newVal, newValDiags := reflect.OutOf(ctx, attrType, val)
  // ...
}

// tfsdk/state.go
func (s *State) SetAttribute(ctx context.Context, path *tftypes.AttributePath, val interface{}) []*tfprotov6.Diagnostic {
  // ...
  newVal, newValDiags := reflect.OutOf(ctx, attrType, val)
  // ...
}

// internal/reflect/outof.go
func OutOf(ctx context.Context, typ attr.Type, val interface{}) (attr.Value, []*tfprotov6.Diagnostic) {
	return FromValue(ctx, typ, val, tftypes.NewAttributePath())
}

Expected Behavior

Attribute path information is correctly set during SetAttribute() reflection.

Actual Behavior

Attribute path information is missing.

It seems like reflect.OutOf() should accept *tftypes.AttributePath as a parameter since the only implementations are:

  • (Plan).Set()
  • (Plan).SetAttribute()
  • (State).Set()
  • (State).SetAttribute()

References

Found while implementing #127 and seeing unexpected test results:

--- FAIL: TestStateSetAttribute (0.00s)
    --- FAIL: TestStateSetAttribute/AttrTypeWithValidateWarning (0.00s)
        state_test.go:1588: unexpected diagnostics (+wanted, -got):   []*tfprotov6.Diagnostic{
                &{
                        Severity:  s"WARNING",
                        Summary:   "Warning Diagnostic",
                        Detail:    "This is a warning.",
            -           Attribute: s"",
            +           Attribute: s`AttributeName("name")`,
                },
                &{Severity: s"WARNING", Summary: "Warning Diagnostic", Detail: "This is a warning.", Attribute: s`AttributeName("name")`},
              }
@bflad bflad added the bug Something isn't working label Sep 3, 2021
@bflad bflad self-assigned this Sep 7, 2021
@bflad bflad added this to the v0.3.0 milestone Sep 7, 2021
bflad added a commit that referenced this issue Sep 7, 2021
@bflad bflad closed this as completed in #133 Sep 8, 2021
bflad added a commit that referenced this issue Sep 8, 2021
…e).SetAttribute() reflection diagnostics (#133)

Reference: #128
@github-actions
Copy link

github-actions bot commented Oct 9, 2021

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.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
1 participant