fix: reject select with only false fields to prevent empty SELECT SQL#2401
fix: reject select with only false fields to prevent empty SELECT SQL#2401
Conversation
…#2344) When all fields in `select` are set to `false`, the query builder generates an empty SELECT clause (`select from "Table"`) causing a SQL syntax error. This adds input validation to reject such payloads with a clear error message. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Claude finished @ymc9's task —— View job Code Review Complete ✅I've thoroughly reviewed PR #2401 that addresses the empty SELECT SQL issue. Here's my comprehensive feedback: OverviewThis PR successfully fixes issue #2344 by adding validation to reject ✅ Strengths
🔍 Technical AnalysisValidation Logic ( private refineForSelectHasTruthyField(schema: ZodType) {
return schema.refine((value: any) => {
const select = value['select'];
if (!select || typeof select !== 'object') {
return true;
}
return Object.values(select).some((v) => v);
}, '"select" must have at least one truthy value');
}Strengths:
Edge Case Considerations:
📝 Minor Code Quality Notes
🏃♂️ Performance Assessment
🔒 Security Assessment
🧪 Test QualityThe regression test is well-structured:
📋 Todo List Status:
🎯 Final VerdictLGTM - This is a solid, well-implemented fix that:
The solution is production-ready and should prevent the SQL syntax errors described in issue #2344. |
📝 WalkthroughWalkthroughThis PR fixes a bug where ORM queries with select objects containing only false values (e.g., Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 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 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.
🧹 Nitpick comments (1)
tests/regression/test/issue-2344.test.ts (1)
1-43: Regression test is well-structured and validates the core fix correctly.The three cases (all-false reject, all-false reject with full field list, mixed pass) directly correspond to the reported issue and the new refinement logic. No issues found.
One optional improvement: the validation is also applied to
create,update,upsert, anddelete(all of which accept aselectfield), but none of those paths are exercised here. Extending the test with at least one mutation operation would ensure regression coverage doesn't erode if a future refactor removes the refinement from a non-find path.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/regression/test/issue-2344.test.ts` around lines 1 - 43, Add a mutation case to the regression test to exercise validation of select on mutation operations: update the test in issue-2344.test.ts to include at least one mutation (e.g., call db.user.update or db.user.create/updateMany/upsert/delete with a select containing all-false and assert it rejects with the same /"select" must have at least one truthy value/ error), and also include a mixed true/false select mutation that succeeds to mirror the find* checks; reference the existing db.user.create used to seed data and the db.user.update/db.user.upsert (or db.user.create with select) call sites to locate where to add the new assertions.
🤖 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/regression/test/issue-2344.test.ts`:
- Around line 1-43: Add a mutation case to the regression test to exercise
validation of select on mutation operations: update the test in
issue-2344.test.ts to include at least one mutation (e.g., call db.user.update
or db.user.create/updateMany/upsert/delete with a select containing all-false
and assert it rejects with the same /"select" must have at least one truthy
value/ error), and also include a mixed true/false select mutation that succeeds
to mirror the find* checks; reference the existing db.user.create used to seed
data and the db.user.update/db.user.upsert (or db.user.create with select) call
sites to locate where to add the new assertions.
ℹ️ Review info
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/orm/src/client/zod/factory.tstests/regression/test/issue-2344.test.ts
fixes #2344
When all fields in
selectare set tofalse, the query builder generates an empty SELECT clause (select from "Table") causing a SQL syntax error. This adds input validation to reject such payloads with a clear error message.Summary by CodeRabbit