Skip to content

fix: wrap WHERE conditions in parentheses when soft-delete AND WhereOr are combined#1347

Open
CyJaySong wants to merge 1 commit intouptrace:masterfrom
CyJaySong:fix-1321
Open

fix: wrap WHERE conditions in parentheses when soft-delete AND WhereOr are combined#1347
CyJaySong wants to merge 1 commit intouptrace:masterfrom
CyJaySong:fix-1321

Conversation

@CyJaySong
Copy link

for #1321

When using WhereOr() with a soft-delete model, the AND deleted_at IS NULL condition was only binding to the last OR branch due to SQL operator precedence, allowing soft-deleted records to be returned through other OR branches.

Fix: track whether any WHERE condition uses OR separator via a whereHasOr flag on whereBaseQuery. When soft-delete or whereFields conditions need to be ANDed, wrap user WHERE conditions in parentheses if OR is present.

Before: WHERE (cond1) OR (cond2) AND deleted_at IS NULL
After: WHERE ((cond1) OR (cond2)) AND deleted_at IS NULL

Also save/restore the whereHasOr flag in WhereGroup to prevent group-internal OR conditions from incorrectly triggering the outer wrapping.

…r are combined (uptrace#1321)

When using WhereOr() with a soft-delete model, the AND deleted_at IS NULL
condition was only binding to the last OR branch due to SQL operator precedence,
allowing soft-deleted records to be returned through other OR branches.

Fix: track whether any WHERE condition uses OR separator via a whereHasOr flag
on whereBaseQuery. When soft-delete or whereFields conditions need to be ANDed,
wrap user WHERE conditions in parentheses if OR is present.

Before: WHERE (cond1) OR (cond2) AND deleted_at IS NULL
After:  WHERE ((cond1) OR (cond2)) AND deleted_at IS NULL

Also save/restore the whereHasOr flag in WhereGroup to prevent group-internal
OR conditions from incorrectly triggering the outer wrapping.
@CyJaySong CyJaySong changed the title fix: wrap WHERE conditions in parentheses when soft-delete AND WhereO… fix: wrap WHERE conditions in parentheses when soft-delete AND WhereOR Mar 18, 2026
@CyJaySong CyJaySong changed the title fix: wrap WHERE conditions in parentheses when soft-delete AND WhereOR fix: wrap WHERE conditions in parentheses when soft-delete AND WhereOr are combined Mar 18, 2026
@CyJaySong
Copy link
Author

@vmihailenco

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant