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

internal/schemavalidator: Fix bug where unknown values were returning error diagnostics too early #252

Merged
merged 2 commits into from
Dec 12, 2024

Conversation

austinvalle
Copy link
Member

@austinvalle austinvalle commented Dec 12, 2024

Closes #251

This PR introduces a small fix to the internal/schemavalidator package (used by all of the type specific equivalents), where unknown values were being treated as if they were known "not null" values, thus raising early diagnostics where they may not be valid (see linked issue).

This fix was made to ConflictsWith and AlsoRequires, but I also added tests to the other already working schema validators. Eventually when #250 lands, we can update these validators to check for the "not null refinement", to reintroduce earlier diagnostics accurately for unknown values.

Test errors prior to fix:

--- FAIL: TestConflictsWithValidatorValidate (0.00s)
--- FAIL: TestConflictsWithValidatorValidate/self-is-unknown (0.00s)

/Users/austin.valle/code/terraform-plugin-framework-validators/internal/schemavalidator/conflicts_with_test.go:287: expected no error(s), got 1: [{{Attribute "foo" cannot be specified when "bar" is specified Invalid Attribute Combination} {[bar]}}]
--- FAIL: TestAlsoRequiresValidatorValidate (0.00s)
--- FAIL: TestAlsoRequiresValidatorValidate/self-is-unknown (0.00s)

/Users/austin.valle/code/terraform-plugin-framework-validators/internal/schemavalidator/also_requires_test.go:286: expected no error(s), got 1: [{{Attribute "foo" must be specified when "bar" is specified Invalid Attribute Combination} {[bar]}}]

@austinvalle austinvalle added the bug Something isn't working label Dec 12, 2024
@austinvalle austinvalle added this to the v0.16.0 milestone Dec 12, 2024
@austinvalle austinvalle requested a review from a team as a code owner December 12, 2024 20:18
@austinvalle austinvalle changed the title internal/schemavalidator: Fix bug where unknown values were returning… internal/schemavalidator: Fix bug where unknown values were returning error diagnostics too early Dec 12, 2024
@austinvalle austinvalle merged commit b500ce7 into main Dec 12, 2024
6 checks passed
@austinvalle austinvalle deleted the av/fix-unknown-bug branch December 12, 2024 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conflicts_with fails during Validate even if one of the values is Unkown
2 participants