-
-
Notifications
You must be signed in to change notification settings - Fork 18
Fix SQL syntax error when select contains only false fields (including nested queries) #657
base: dev
Are you sure you want to change the base?
Conversation
Co-authored-by: jiashengguo <16688722+jiashengguo@users.noreply.github.com>
Co-authored-by: jiashengguo <16688722+jiashengguo@users.noreply.github.com>
| select: { id: false } as any, | ||
| }); | ||
| expect(r3).toBeNull(); | ||
| }); |
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.
@copilot
Add the case that this false select is in the nested query
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.
Added test case for nested queries with only false fields in commit 3adea0a. The fix now handles both top-level and nested relation queries properly - empty objects are filtered out in the result processor for array relations.
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.
Pull request overview
This PR fixes a SQL syntax error that occurred when queries used select with only false values (e.g., select: { id: false }), which would generate invalid SQL like SELECT FROM "User".
Changes:
- Added early return in
read()method to handle cases where all select fields are explicitly set to false - Added comprehensive test coverage for
findMany,findFirst, andfindUniqueoperations with only false select fields
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/orm/src/client/crud/operations/base.ts | Adds validation check to return empty array when all select fields are false, preventing invalid SQL generation |
| tests/e2e/orm/client-api/find.test.ts | Adds test case verifying correct behavior (empty array for findMany, null for findFirst/findUnique) when all select fields are false |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: jiashengguo <16688722+jiashengguo@users.noreply.github.com>
Co-authored-by: jiashengguo <16688722+jiashengguo@users.noreply.github.com>
|
@copilot could you check Prisma ORM's behavior for this usage? For both top-level select and nested relation select. |
I tested Prisma ORM's behavior with select containing only false fields: Prisma ORM behavior:
Current implementation (this PR):
Should we align with Prisma's behavior and throw a validation error instead? This would be a breaking change from the current implementation but would match Prisma's API expectations. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Queries with
select: { id: false }generate invalid SQL (SELECT FROM "User") when all fields are explicitly excluded, causing database errors. This PR fixes the issue for both top-level and nested relation queries.Changes
Core fix (
packages/orm/src/client/crud/operations/base.ts):[]fromread()when all select fields are falseFindOperationHandlertransforms this correctly:[]forfindMany,nullforfindFirst/findUniqueNested query fix (
packages/orm/src/client/crud/dialects/lateral-join-dialect-base.tsandpackages/orm/src/client/result-processor.ts):buildRelationObjectArgs()to detect when all select fields are false in nested relationsprocessRelation()to remove empty objects from array relationsTest coverage (
tests/e2e/orm/client-api/find.test.ts):findMany,findFirst, andfindUniquewith only false fieldsExample
Original prompt
selectparams zenstack#2344✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.