fix(orm): enum field filter inside typed JSON compared as raw JSON - #2776
fix(orm): enum field filter inside typed JSON compared as raw JSON#2776ymc9 wants to merge 1 commit into
Conversation
Enum values are stored as JSON strings, but filtering by an enum-typed field of a typed JSON field compared the JSON-extracted value directly against the bare enum literal, failing on Postgres with "invalid input syntax for type json" and silently matching nothing on SQLite. Apply the same cast-to-text + quote-trim treatment used for String fields. Fixes #2755 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe ORM now trims surrounding quotes from enum values in typed JSON filters before primitive filter construction. A regression test covers equality, negation, and inclusion queries across SQLite and PostgreSQL. ChangesTyped JSON enum filtering
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/regression/test/issue-2755.test.ts`:
- Around line 50-54: Add a regression assertion in the bKP.findMany tests for
the filter-builder’s notIn branch, using proposal.bkpType.notIn with
['CAPSTONE'] and asserting that only the record with id '2' is returned.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: dcf83742-e96b-4fc8-ba02-97cdbcccd6e4
📒 Files selected for processing (2)
packages/orm/src/client/crud/dialects/base-dialect.tstests/regression/test/issue-2755.test.ts
| await expect( | ||
| db.bKP.findMany({ | ||
| where: { proposal: { bkpType: { in: ['CAPSTONE', 'OTHER'] } } }, | ||
| }), | ||
| ).resolves.toEqual([expect.objectContaining({ id: '1' }), expect.objectContaining({ id: '2' })]); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Add an explicit notIn regression case.
The PR claims support for notIn, but this suite only covers equals, not, and in. notIn has its own filter-builder branch, so add an assertion that notIn: ['CAPSTONE'] returns only record 2. The PR objective explicitly includes notIn.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/regression/test/issue-2755.test.ts` around lines 50 - 54, Add a
regression assertion in the bKP.findMany tests for the filter-builder’s notIn
branch, using proposal.bkpType.notIn with ['CAPSTONE'] and asserting that only
the record with id '2' is returned.
Fixes #2755
Problem
Filtering by an enum-typed field inside a typed JSON field failed:
On PostgreSQL this threw
invalid input syntax for type json(the JSON-extracted value was compared directly against the bare enum literal), and on SQLite it silently matched nothing (quoted JSON text"CAPSTONE"never equalsCAPSTONE).Fix
In
buildTypeJsonNonArrayFilter, the cast-to-text + quote-trim treatment applied toStringfields is extended to enum fields, since enum values are stored as JSON strings. The comparison then flows throughbuildEnumFilteron a plain-text receiver, coveringequals,not,in, andnotIn.Testing
tests/regression/test/issue-2755.test.tscovering direct equality,not, andinfilters on both SQLite and PostgreSQL (failed with the issue's exact error before the fix).json-filter.test.tsandtyped-json-fields.test.tspass on both SQLite and PostgreSQL.🤖 Generated with Claude Code
Summary by CodeRabbit