Using clause.Not and clause.And result in erroneous simplification #767
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using clause.Not and clause.And to create query Where conditions and faulty simplification is applied:
NOT(col1 = val1 AND col2 = val2)
gets turned into(col1 <> val1 AND col2 <> val2)
, which is wrong.The right simplification is to turn the AND into an OR, by De Morgan's Laws, so
(col1 <> OR val1 AND col2 <> val2)
This is a regression that was introduced into gorm in 1.25.6. Testing against 1.25.5 returns the correct condition and expected rows in the included tests.
(This PR includes changes to the go.mod file to be able to compile as per #751, so it assumes the gorm.io/gen repo has been cloned into the ./gen folder. Additionally, there are some replaces to make sure testing against 1.25.5 can compile, tests still fail against gorm master with and without these replaces).