fix(policy): support in operator against enum list with native enums#2723
Conversation
…list When an `in` policy expression compares a native enum column against a list of enum literals (e.g. `state in [DONE, REVIEWED]`), the right-hand array is built with enum elements reduced to text, but the enum column kept its native type. PostgreSQL then rejected the comparison with `operator does not exist: "MyEnum" = text`. Cast the enum column to text so it matches the text[] array. Non-enum fields and databases without native enum types (SQLite/MySQL) are unaffected. Fixes #2718 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe fix updates the policy expression transformer's ChangesEnum cast fix for
CI workflow update and test refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
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-2718.test.ts`:
- Around line 41-59: The createPolicyTestClient function call is missing an
explicit provider parameter, which causes it to default to getTestDbProvider()
that may return a non-SQLite provider and skip the intended SQLite code path for
this regression test. Add an explicit provider parameter to the
createPolicyTestClient call to pin it to SQLite, ensuring the test exercises the
specific SQLite behavior that this regression case is designed to validate.
🪄 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
Run ID: 401905ee-ba64-4f7b-b40f-61613a03a726
📒 Files selected for processing (2)
packages/plugins/policy/src/expression-transformer.tstests/regression/test/issue-2718.test.ts
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 @.github/workflows/claude-code-review.yml:
- Line 32: Replace the mutable version tag `@v1` in the
anthropics/claude-code-action reference with a specific commit SHA to prevent
potential security risks from upstream repository compromises. Add a comment on
the line above the uses statement indicating the version that the commit SHA
corresponds to for maintainability and future reference when updating.
🪄 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
Run ID: 72fe6428-04dc-4ca0-99fc-d939ca9cebd9
📒 Files selected for processing (1)
.github/workflows/claude-code-review.yml
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-2669.test.ts`:
- Line 5: The describe function in the test suite has a misleading title that
includes the ($provider) placeholder, which is no longer relevant since the test
suite no longer parameterizes providers. Remove the ($provider)` text from the
describe function title string to make the test reporting clearer and more
accurate. Keep the rest of the title "Regression for issue 2669" but remove the
stale placeholder to reflect that this is now a concrete test suite, not a
parameterized one.
🪄 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
Run ID: c7b9cb8e-c578-4d8b-a102-6f9df09e8b02
📒 Files selected for processing (1)
tests/regression/test/issue-2669.test.ts
Problem
When an
inpolicy expression compares a native enum column against a list of enum literals, e.g.:the generated SQL is
"state" = any(cast(ARRAY[$1,$2] as text[])). The right-hand array is built with enum elements reduced totext, but the left-hand enum column kept its native enum type, so PostgreSQL rejected the comparison:The
==operator was unaffected because it routes throughbuildComparison, which already reconciles enum type compatibility. (Workaround in the issue was rewritingin [DONE, REVIEWED]asstate == DONE || state == REVIEWED.)Fix
In the
in/array-contains branch of the expression transformer, cast the left operand to text viadialect.castTextwhen it is a native enum column, so it matches thetext[]array. Non-enum fields and databases without native enum types (SQLite/MySQL) are unaffected.Tests
Added
tests/regression/test/issue-2718.test.ts:@@deny('delete', ...)rule (fails before the fix, passes after).@@allow('read', state in [DONE, REVIEWED])to guard the non-native-enum path.Existing policy e2e tests (incl.
supports in with field,collection-predicate,isempty-function-pg) pass, andtsc --noEmiton the policy package is clean.Fixes #2718
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
inoperator handling when comparing enum fields against inline lists, ensuring consistent policy behavior across supported database engines.Tests
in+ enum inline-list scenario, verifying expected allow/deny and null-read behavior on both PostgreSQL and SQLite.