fix(drizzle): preserve both top-level and/or clauses in where queries - #17495
Open
Osamaali313 wants to merge 1 commit into
Open
fix(drizzle): preserve both top-level and/or clauses in where queries#17495Osamaali313 wants to merge 1 commit into
Osamaali313 wants to merge 1 commit into
Conversation
parseParams assigned `result` directly for each top-level `and`/`or` key, so a where object containing both an `and` and an `or` key at the same level kept only whichever was iterated last, silently dropping the other clause. AND the built groups together instead (matching how field-path constraints already combine, and how the MongoDB adapter preserves both keys). Single `and` / single `or` queries produce identical output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What?
In the SQL adapters (
@payloadcms/drizzle), awherequery that has both a top-levelandkey and a top-levelorkey silently drops one of them. Only the clause that happens to be iterated last is applied.(status = 'published' OR status = 'featured') AND views > 100views > 100only — the entireOR (status …)restriction is dropped (reverse the key order and theANDclause is dropped instead), so the query returns rows that should have been filtered out.Why?
In
packages/drizzle/src/queries/parseParams.ts, each top-leveland/orkey did a bare assignment:Field-path constraints accumulate into
constraints[]and are ANDed at the end, but the two array-keys overwrite the singleresult, so the first is lost. The MongoDB adapter (packages/db-mongodb/src/queries/parseParams.ts) stores them under separate$and/$orkeys and keeps both — so the same valid query returns different result sets on Postgres/SQLite vs MongoDB.How?
AND the built groups together instead of overwriting:
Single-
andand single-orqueries produce byte-identical output; only the both-keys case changes (from dropping a clause to keeping both). Nested forms (and: [{ or: [...] }]) were already fine.Verified with a standalone repro of the loop + end-combine (sibling
or+andnow keeps both; single-key output unchanged). I did not add an integration test because the where-query suite (test/database/int.spec.ts) runs against live DB adapters and I couldn't run it locally — happy to add one there if you'd like.Fixes #