Skip to content
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

Introduce attr.TypeWithValidate handling to internal/reflect and tfsdk #82

Merged
merged 13 commits into from
Aug 10, 2021

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Jul 27, 2021

Reference: #17

The next step will be deciding how to handle the returned diagnostics since there can be multiple warnings and/or errors, however these callers return a single error type.

@paddycarver
Copy link
Contributor

these callers return a single error type.

If it's cleaner/better that they return Diagnostics, I think that's at least worth exploring as an option.

@bflad
Copy link
Contributor Author

bflad commented Jul 29, 2021

Something that might also be worth considering with this type of validation is what might happen if a type wants to introduce a non-backwards compatible change. Warning diagnostics are a good approach to prepare practitioners for such a change, but if in a major provider release the change occurs, errors during state reading operations could leave practitioners in a tough spot without first applying/refreshing an updated value on the older version.

@paddycarver
Copy link
Contributor

Hmmmm, yeah, that's a solid point. Would we want to introduce migrations in that case? Do we want to validate on read? I think we have to, right, to ensure we have the appropriate value for the type? 🤔 I think providers could work around it with state migrations, but that may not be ideal.

Reference: #17

The next step will be deciding how to handle the returned diagnostics since there can be multiple warnings and/or errors, however these callers return a single error type.
@bflad bflad force-pushed the f-attr-Type-Validate branch from 4a98028 to 0d1c015 Compare July 30, 2021 17:02
…and state handling

Required making the following diagnostics aware:

- `internal/reflect`
- `tfsdk.Config`
- `tfsdk.Plan`
- `tfsdk.State`
- `(types.List).ElementsAs()`
- `(types.Map).ElementsAs()`
- `(types.Object).As()`
@bflad bflad force-pushed the f-attr-Type-Validate branch from 9455177 to 5c6d44c Compare July 30, 2021 18:58
@bflad bflad marked this pull request as ready for review July 30, 2021 19:02
@bflad bflad requested a review from a team July 30, 2021 19:02
@bflad
Copy link
Contributor Author

bflad commented Jul 30, 2021

I still need to circle through all the places that are introducing the attr.TypeWithValidation handling and add covering unit testing that diagnostics are surfaced, but the code should be mostly there.

@bflad bflad self-assigned this Aug 2, 2021
@bflad
Copy link
Contributor Author

bflad commented Aug 2, 2021

This is ready, @kmoe!

@bflad bflad removed their assignment Aug 2, 2021
internal/reflect/interfaces.go Outdated Show resolved Hide resolved
internal/reflect/pointer_test.go Outdated Show resolved Hide resolved
internal/testing/types/bool.go Show resolved Hide resolved
tfsdk/config_test.go Show resolved Hide resolved
tfsdk/config_test.go Outdated Show resolved Hide resolved
types/diags.go Outdated Show resolved Hide resolved
@bflad bflad requested review from paddycarver and kmoe August 6, 2021 13:52
Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good. Great work, @bflad. I think once merged we're committing ourselves to tackling #24 before release, though, as people will need to know, at the very least, if Get and Set (etc.) are returning errors they should abort on or warnings they should roll through. I think that's okay, though.

@bflad bflad added this to the v0.3.0 milestone Aug 10, 2021
@bflad bflad merged commit 8cc9eb6 into main Aug 10, 2021
@bflad bflad deleted the f-attr-Type-Validate branch August 10, 2021 14:22
@bflad bflad mentioned this pull request Aug 10, 2021
@paddycarver paddycarver mentioned this pull request Aug 16, 2021
@github-actions
Copy link

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.
If you have found a problem that seems related to this change, 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 Sep 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants