Skip to content

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

Open
CyJaySong wants to merge 1 commit into
uptrace: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 into
uptrace:masterfrom
CyJaySong:fix-1321

Conversation

@CyJaySong
Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

@vmihailenco

@CyJaySong
Copy link
Copy Markdown
Contributor Author

@Aoang Please review it

@Aoang
Copy link
Copy Markdown
Collaborator

Aoang commented Apr 8, 2026

@Aoang Please review it

I'm sorry for the delayed response. Please understand that the maintainers of this library are not working on it full-time.

I did see this PR during the initial round of review, but for various reasons I didn't provide feedback at the time.

One of the most challenging aspects of maintaining an open-source library is that we design it based on the scenarios we anticipate, while trying to support as many use cases as possible — yet we can never know every user's specific situation.

There's no doubt that this is a bug and it should be fixed. However, the fix involves a breaking change. After users update the dependency, they won't receive any obvious warning or error, which makes it quite risky.

I believe the other maintainers are also carefully evaluating the scope and impact of this PR, and considering whether there's a better, less disruptive solution.

This kind of assessment takes time, and sometimes a bit of luck too, as it significantly reduces the time available for deep consideration.

Thank you for your efforts, and please be patient with us.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this pr will be closed. Please feel free to give a status update now, ping for review, when it's ready. Thank you for your contributions!

@github-actions github-actions Bot added the stale label May 9, 2026
@CyJaySong
Copy link
Copy Markdown
Contributor Author

refresh

@github-actions github-actions Bot removed the stale label May 10, 2026
@bevzzz
Copy link
Copy Markdown
Collaborator

bevzzz commented May 13, 2026

I will add my review later this week @Aoang

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.

3 participants