-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
internal/fwschemadata: Rewrite SetValue
semantic equality logic to ignore order
#1064
Conversation
̶S̶i̶n̶c̶e̶ ̶w̶e̶ ̶h̶a̶v̶e̶ ̶w̶r̶i̶t̶e̶-̶o̶n̶l̶y̶ ̶a̶t̶t̶r̶i̶b̶u̶t̶e̶s̶ ̶l̶a̶n̶d̶i̶n̶g̶ ̶s̶o̶o̶n̶,̶ ̶t̶h̶i̶s̶ ̶b̶u̶g̶ ̶f̶i̶x̶ ̶w̶i̶l̶l̶ ̶g̶o̶ ̶i̶n̶ ̶a̶f̶t̶e̶r̶ ̶i̶n̶ ̶ Now planning on going with write-only attributes in |
I read line-by-line through With that, I think I have unlocked the power-up needed to review the PR 😃 |
Non-blocking for merge, simply a consideration: is this for optimization or correctness? I'm guessing optimization -- I think the behavior is still correct without doing this. Related: A set might contain the same value more than once. Or multiple semantically-equal values. And I imagine it's a Hard (and unnecessary) Problem to make any promise about the behavior in that case. If the behavior mattered in that scenario, we'd likely advise folks to use a |
e28c810
to
fef2d6a
Compare
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.
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.
I see the CI / lint Action wants something from us -- I'm happy to stamp this again if/when needed.
Will create a new PR for lint deprecations since it's gonna be noisy and unrelated to these changes 👍🏻 |
Closes #1061
This PR fixes the set semantic equality logic, which prior to this change, was written equivalent to list semantic equality.
Sets are unordered, so to correctly compare the semantic equality of two sets, we must compare each element in the set against all other elements to determine if there is a semantically equivalent element in the set. Once we find a semantically equal element, we remove it from the slice of candidates and continue.
As an example, consider a set of case insensitive strings.
With the previous logic, the following sets would be considered semantically equal:
However the following set would be incorrectly considered semantically not equal, due to the difference in order:
This change will result in both of these examples being considered semantically equal.
Corner tests
I also wrote some acceptance tests to make it a little easier to understand the impact (using IPv6 address strings as an example)
hashicorp/terraform-provider-corner#297
Unit test failures before the fix
https://github.com/hashicorp/terraform-plugin-framework/actions/runs/12832297072/job/35784696031?pr=1064