-
-
Notifications
You must be signed in to change notification settings - Fork 128
fix: handle String[] array fields correctly in PostgreSQL policy queries #2331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fix issue zenstackhq#2328 where String[] fields cause PostgreSQL syntax errors when combined with policy guards in WHERE clauses. The issue was that when select is undefined, Prisma selects all fields but generates invalid PostgreSQL SQL for array fields. By explicitly setting select to include all fields (including arrays) instead of using undefined, Prisma generates correct SQL. Changes: - Replace select = undefined with explicit makeAllFieldSelect() call - Add makeAllFieldSelect() method that includes all scalar fields including arrays - Preserves all existing behavior while fixing the SQL generation bug
📝 WalkthroughWalkthroughWhen a schema is present, selection logic now deterministically selects all scalar fields via a new helper; otherwise it falls back to the existing ID-only selection. The previous fallback that forced scalar selection when Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: Repository UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (2)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/runtime/src/enhancements/node/policy/policy-utils.ts (1)
1262-1280: Consider consolidating withmakeAllScalarFieldSelect.The new
makeAllFieldSelectmethod has an identical implementation to the existingmakeAllScalarFieldSelectmethod (lines 1249-1260). Both iterate over model fields and include only non-data-model (scalar) fields.Consider reusing the existing method or consolidating them to reduce duplication:
🔎 Proposed refactor
- /** - * Creates a select object that includes all fields (scalar and array) for the model. - * This is used instead of undefined to ensure Prisma handles array fields correctly - * when generating PostgreSQL SQL queries with WHERE clauses. - */ - private makeAllFieldSelect(model: string): any { - const fields = this.getModelFields(model); - const result: any = {}; - if (fields) { - Object.entries(fields).forEach(([k, v]) => { - // Include all scalar fields (including arrays) - explicitly setting select - // instead of undefined ensures Prisma generates correct SQL - if (!v.isDataModel) { - result[k] = true; - } - }); - } - return result; - }Then update line 897 to use the existing method:
- select = this.makeAllFieldSelect(model); + select = this.makeAllScalarFieldSelect(model);
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/runtime/src/enhancements/node/policy/policy-utils.ts
🔇 Additional comments (1)
packages/runtime/src/enhancements/node/policy/policy-utils.ts (1)
891-906: LGTM!The conditional logic correctly differentiates between schema validation (requiring all fields) and policy-only checks (requiring only ID fields). The spread-based merge for
entityChecker.selectorproperly combines the selections.
Fix issue #2328 where String[] fields cause PostgreSQL syntax errors when combined with policy guards in WHERE clauses.
The issue was that when select is undefined, Prisma selects all fields but generates invalid PostgreSQL SQL for array fields. By explicitly setting select to include all fields (including arrays) instead of using undefined, Prisma generates correct SQL.
Changes: