Skip to content

A filter object that mixes an in list, a not-null test or a range fails instead of dropping a condition - #2311

Merged
marvin-bitterlich merged 1 commit into
mainfrom
ccr-efcafb6c-sxkls9-sql-filter-in-not
Nov 18, 2026
Merged

marvin-bitterlich merged 1 commit into
mainfrom
ccr-efcafb6c-sxkls9-sql-filter-in-not

Conversation

@marvin-bitterlich

Copy link
Copy Markdown
Contributor

Why?

A repository filter object that mixes operators was not always refused. With an in list present, every other key in the object was dropped without a word:

Filter Before Now
read { note: { in: ["paid"], not: null } } compiles, runs with the list alone compile error, SchemaError
delete({ id: { in: [1, 2], gt: 1 } }) from a variable or untyped input removes rows 1 and 2 SchemaError, removes nothing
read { value: { gt: 1, in: [1, 2] } } compiles, SchemaError compile error, SchemaError
read { note: { like: "p%", not: null } } compiles, SchemaError compile error, SchemaError
upsert updateWhere: { updatedAt: { excluded: "updatedAt", gte: since } } compiles, compares for equality only compiles, SchemaError

The delete row is the one that can hurt: the caller asked for less than was removed.

How?

At run time, the shared predicate in repositoryFilter.ts refuses a key beside in with the same SchemaError (an unexpected key at field.key) that the range branch already used. A reference to the incoming row, { excluded: "field" }, is now a reference only when it is the object's one key, so a range beside it reaches the existing refusal. findMany, findOne, count, select, aggregate, delete, deleteBatched, latestPerGroup and updateWhere all build their where from this predicate.

At the type level, each operator shape now rules out the keys of the others: a list takes nothing beside in, { not: null } takes nothing beside not, and ranges with a pattern take neither in nor not. Inference is unchanged; repositoryFilter.typecheck.test.ts still checks the result types of the same calls. The shapes moved to filterOperators.ts because repositoryFilter.ts went over the 150-line limit.

Combinations that worked stay as they were: several ranges with a pattern in one object, and a JSON field whose schema accepts the object, which still compares it as a value.

Stories run against real PostgreSQL: postgresMixedOperators.spec.ts for findMany, the prepared select, aggregate and delete (which also reads back that no row was removed), and one more in postgresConditionalUpsert.spec.ts. Each new story fails on main except "an in list beside a range" on reads, which main already refused and which is there as a guard. The typecheck cases are in repositoryFilter.typecheck.test.ts and conditionalUpsert.typecheck.test.ts; on main every one of them compiled.

Decisions

  • Minor with a ### Breaking entry, not a patch. { in: [...], not: null } on a nullable field compiled and returned the right rows, because a list match already leaves out null. It now fails to compile and fails at run time. The migration is to remove not: null. Everything else that stops compiling failed at run time before or dropped a condition.
  • A key beside in is refused whatever it is, including a key with an undefined value and a key that names no operator. { not: null } already counted keys this way.
  • { excluded, ... } in a conditional upsert's updateWhere is included at run time only. It is the same predicate and the same silent drop. Its types still accept the mix: closing that would put an excluded?: never key on the read filter shapes, which have no such concept.

Callouts

  • Comparisons is an exported type and now carries in?: never and not?: never. A consumer that builds on it for its own operator objects gets the stricter shape.
  • The new module filterOperators.ts is reachable as @shivaedev/sql/filterOperators.ts like every source file of the package. It holds types only.
  • deleteBatched and latestPerGroup share the predicate and the types but have no story of their own for a mixed object.

Generated by Claude Code

…ls instead of dropping a condition

With `in` present, every other key of the operator object was ignored:
`{ in, not: null }` compiled and ran as the list alone, and `delete`
with a key beside `in` from untyped input removed the whole list. A
conditional upsert ignored a range beside `{ excluded }`.

The shared predicate now fails with the SchemaError other invalid
filters use, and each operator shape rules out the keys of the others
at the type level. The shapes moved to filterOperators.ts to keep
repositoryFilter.ts under the line limit.

`{ in, not: null }` compiled and returned the right rows before, so the
changeset is minor with a Breaking entry.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VjCSiB3Dk7BRBmjic6wFM5
@tally-code-quality

Copy link
Copy Markdown

Coverage 92.0% (±0.0 pts) · Patch 100.0%

All 7 added lines are covered.

f177864 (merged onto 64d4061) vs main at 64d4061 · updated Nov 18, 16:23 UTC · Full report

@marvin-bitterlich
marvin-bitterlich added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 7a56345 Nov 18, 2026
20 checks passed
@marvin-bitterlich
marvin-bitterlich deleted the ccr-efcafb6c-sxkls9-sql-filter-in-not branch November 18, 2026 16:33
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.

2 participants