fix(policy): support now() default value in access policy evaluation#2465
fix(policy): support now() default value in access policy evaluation#2465
Conversation
- Fill now() default in evalGenerator so createdAt fields are populated before policy checks, preventing DefaultInsertValueNode from being treated as null during pre-create policy evaluation. - Fix now() SQL function to produce ISO 8601 format matching each dialect's DateTime storage format (SQLite: strftime, MySQL: DATE_FORMAT with trimmed microseconds), ensuring correct comparisons in policy expressions. - Add e2e tests for now() in create, read, update, and delete policies. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Claude finished @ymc9's task —— View job Code Review Complete ✅I've thoroughly reviewed this pull request that adds support for Review Tasks
✅ Overall Assessment: Excellent ImplementationThis PR effectively solves the core issue where Code Quality & Best Practices
|
📝 WalkthroughWalkthroughThe pull request adds dialect-aware support for a Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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.
🧹 Nitpick comments (1)
tests/e2e/orm/policy/now-function.test.ts (1)
18-19: Minor: Comment doesn't match the actual policy.The comment references "satisfying the <= now() check" but the policy on line 12 is
createdAt != null. Consider updating the comment to accurately describe what's being tested.- // createdAt should be auto-filled with now(), satisfying the <= now() check + // createdAt should be auto-filled with now(), satisfying the != null check🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/e2e/orm/policy/now-function.test.ts` around lines 18 - 19, The comment above the test is inaccurate: it mentions "satisfying the <= now() check" but the policy being tested is `createdAt != null`; update the comment to accurately describe the assertion (e.g., "createdAt should be auto-filled and not null") and ensure it references the actual policy semantics being enforced by db.post.create in this test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/e2e/orm/policy/now-function.test.ts`:
- Around line 18-19: The comment above the test is inaccurate: it mentions
"satisfying the <= now() check" but the policy being tested is `createdAt !=
null`; update the comment to accurately describe the assertion (e.g., "createdAt
should be auto-filled and not null") and ensure it references the actual policy
semantics being enforced by db.post.create in this test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4dd8df9a-95aa-4603-9bf2-227d5913f7b5
📒 Files selected for processing (3)
packages/orm/src/client/crud/operations/base.tspackages/orm/src/client/functions.tstests/e2e/orm/policy/now-function.test.ts
Summary
now()default inevalGeneratorso@default(now())fields are populated before policy checks, preventingDefaultInsertValueNodefrom being treated asnullduring pre-create policy evaluation.now()SQL function to produce ISO 8601 format matching each dialect's DateTime storage format (SQLite:strftime, MySQL:DATE_FORMATwith trimmed microseconds), ensuring correct comparisons in policy expressions.now()in create, read, update, and delete policies.Test plan
@default(now())field used in policy rulenow()publishedAt <= now()expiresAt < now()now()default combined withauth()check in create policy🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
now()as a default value generator for automatic timestamp population in models.now()function with native dialect support for SQLite, MySQL, and PostgreSQL.Tests
now()functionality across CRUD operations and access policies.