Skip to content

fix(db): reject nonliteral right operands in simple comparisons - #2474

Open
XSY-28 wants to merge 1 commit into
TanStack:mainfrom
XSY-28:fix/reject-nonliteral-comparisons
Open

XSY-28 wants to merge 1 commit into
TanStack:mainfrom
XSY-28:fix/reject-nonliteral-comparisons

Conversation

@XSY-28

@XSY-28 XSY-28 commented Nov 24, 2026 •

Copy link
Copy Markdown

🎯 Changes

Fixes #2381. The simple comparison helper now rejects right-hand field references and computed expressions through its existing error path. Literal null is still a filter value, including when the comparison is negated or combined with another supported condition.

🔬 Oracle Coverage

The coverage map records the owner under Simple WHERE comparison extraction. The oracle checks the public helper across 180 histories with six operators, direct and negated forms, and a supported condition before or after the comparison or none.

  • On main, 72 field and computed operands returned null descriptors. The literal controls passed.
  • On the candidate, 224 tests passed across the new oracle and existing expression-helper suite. The named replay and 21 existing manifest and collection-truncate checks also passed. An on-demand loader probe rejected a computed operand before forwarding and retained both descriptors in the literal-null control.
  • Restoring the negated fallback and rejecting literal null each failed 36 histories at the extraction checkpoint.
  • The loader probe covers a local callback. Provider execution and row publication are outside this verification.

✅ Checklist

  • I have tested this code locally with pnpm test.
  • Ran pnpm --filter @tanstack/db test --maxWorkers=2 --coverage.enabled=false with Node 24.8.0 and pnpm 11.1.0. All 56,136 tests in 434 files passed with no type errors.
  • Ran the project pre-commit and the staged size guard.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

AI disclosure: OpenAI Codex (GPT-6.2 Sol, xhigh, standard speed) investigated and authored the change, oracle and coverage record, and ran the validation.

Summary by CodeRabbit

  • Bug Fixes
    • Comparisons with a field or computed value on the right-hand side are now rejected instead of being treated as comparisons with null.
  • Tests
    • Added coverage for supported and rejected comparison forms, including negated comparisons and comparisons combined with other conditions.
  • Documentation
    • Expanded the oracle coverage guide with details about simple comparison coverage.

Field references and computed right operands cannot be represented by a
simple filter descriptor. Use the existing literal extractor in both
comparison branches so those operands take the documented rejection path.

Law
The public extraction helper preserves supported literal filters and rejects
the entire expression when a comparison cannot be represented.

Reach
180 histories cover six operators, direct and negated forms, literal null,
and conjunctions with a supported companion in either position.

RED
72 histories returned a null descriptor for a nonliteral operand.

GREEN
224 extraction and expression-helper tests pass. An on-demand loader probe
rejects the computed comparison before forwarding a filter and retains both
descriptors in the literal-null control.

Mutant
Restoring only the negated fallback fails 36 histories. Rejecting literal
null fails another 36 histories.

Limits
The oracle observes the public helper return or rejection. The loader probe
covers a local callback, with provider execution outside the test scope.

Fixes TanStack#2381
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

extractSimpleComparisons now rejects non-literal right operands in direct and negated comparisons instead of returning them as null. An oracle test covers the supported and rejected operand cases, and the test command and coverage guide include the oracle.

Changes: Simple comparison validation

Layer / File(s) Summary
Reject non-value comparison operands
packages/db/src/query/expression-helpers.ts, .changeset/fruity-mugs-exist.md
Direct and negated comparisons now use extractValue. Non-value operands become undefined and fail the existing validation. The changeset declares a patch release.
Model and register comparison oracle
packages/db/tests/query/simple-comparisons-oracle.test.ts, packages/db/tests/property-registry/db-core.ts, packages/db/package.json, docs/contributing/oracle-coverage.md
The oracle models supported literal and null operands and rejects missing, field, and computed operands. The property registry, test:oracles command, and coverage guide include the oracle.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: kyleamathews, samwillis

Merge Risk: Minimal · up to 2a39b

Comparisons against a column or computed expression are now rejected with the existing "complex expression" error instead of silently filtering on null. Literal null filters keep working. The change is small and covered by a new oracle test, and no unresolved merge-blocking risk remains.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Out of Scope Changes check Inconclusive The core source change in expression-helpers.ts is limited to the two comparison branches named in #2381. The changeset, the test:oracles script entry, the property-registry entry, and the new ora… Confirm whether removing the PR #2196 index-suggestion oracle paragraph from docs/contributing/oracle-coverage.md is intended. If it is not intended, restore that paragraph. Provide a readable diff of that file so the removal can be verif…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title "fix(db): reject nonliteral right operands in simple comparisons" matches the main change. The diff makes extractSimpleComparisons reject field-reference and computed right operands through …
Description check Passed The description follows the repository template. It has the Changes section, an Oracle Coverage section that names the coverage-map owner and gives bug-fix evidence (histories, RED/GREEN counts, probe…
Linked Issues check Passed [#2381] The issue requires extractSimpleComparisons to throw the "Found complex expression" error when a comparison's right operand is a column or computed expression, and to keep returning `value: …
Full details: Title check

Explanation

The title "fix(db): reject nonliteral right operands in simple comparisons" matches the main change. The diff makes extractSimpleComparisons reject field-reference and computed right operands through the existing error path, and keeps literal null as a valid filter value. The title is concise, uses a conventional commit prefix, and names the affected component.

Full details: Description check

Explanation

The description follows the repository template. It has the Changes section, an Oracle Coverage section that names the coverage-map owner and gives bug-fix evidence (histories, RED/GREEN counts, probe scope, and limits), and a checklist with the test command and changeset box checked. It states the violated behavior, the exercised paths, and the remaining limits: provider execution and row publication are not verified. The Oracle Coverage section does not cleanly map to every template prompt, since it does not list observation checkpoints per path in full detail, and the test-run line cites a broader command than the one in the unchecked checklist item. These are minor gaps.

Full details: Linked Issues check

Explanation

[#2381] The issue requires extractSimpleComparisons to throw the "Found complex expression" error when a comparison's right operand is a column or computed expression, and to keep returning value: null for literal null. At the reviewed head, both comparison branches (the plain branch and the not branch) now compute value as rightArg ? extractValue(rightArg) : undefined instead of rightArg?.type === 'val' ? rightArg.value : null. extractValue returns undefined for any non-val node, so ref and func operands fail the existing value !== undefined guard and throw. The not branch throws the 'not(gt)'-style message from the issue. A literal val with value null still passes the guard and yields value: null. The PR also adds an oracle test (simple-comparisons-oracle.test.ts) covering six operators, direct and negated forms, and companion comparisons. I did not run that test. The code change itself was read and matches the issue's expected behavior.

Full details: Out of Scope Changes check

Explanation

The core source change in expression-helpers.ts is limited to the two comparison branches named in #2381. The changeset, the test:oracles script entry, the property-registry entry, and the new oracle test support this fix and are in scope. The AI summary states that docs/contributing/oracle-coverage.md also removes the paragraph documenting the index-suggestion oracle's PR #2196 extension. The PR description does not mention that removal. The diff for that file could not be read because its changed blobs are missing from the checkout, so I cannot confirm whether the removal is an unrelated change or a side effect of the coverage map update.

Resolution

Confirm whether removing the PR #2196 index-suggestion oracle paragraph from docs/contributing/oracle-coverage.md is intended. If it is not intended, restore that paragraph. Provide a readable diff of that file so the removal can be verified.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f1e5fc18-38c1-4f82-ae4e-e73d689057d7
Commits

Reviewing files that changed from the base of the PR and between 371e40d and 2a39b0b.

Files selected for processing: 6

  • .changeset/fruity-mugs-exist.md
  • docs/contributing/oracle-coverage.md
  • packages/db/package.json
  • packages/db/src/query/expression-helpers.ts
  • packages/db/tests/property-registry/db-core.ts
  • packages/db/tests/query/simple-comparisons-oracle.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

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.

extractSimpleComparisons returns value: null when the right side of a comparison isn't a literal

1 participant