Skip to content
This repository was archived by the owner on Feb 10, 2026. It is now read-only.

Conversation

Copy link
Contributor

Copilot AI commented Feb 6, 2026

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):

  • Early return [] from read() when all select fields are false
  • Avoids SQL generation for impossible field selection
  • Existing FindOperationHandler transforms this correctly: [] for findMany, null for findFirst/findUnique

Nested query fix (packages/orm/src/client/crud/dialects/lateral-join-dialect-base.ts and packages/orm/src/client/result-processor.ts):

  • Added check in buildRelationObjectArgs() to detect when all select fields are false in nested relations
  • Added filtering in processRelation() to remove empty objects from array relations
  • Ensures nested queries with only false fields return empty arrays instead of arrays of empty objects

Test coverage (tests/e2e/orm/client-api/find.test.ts):

  • Added test cases covering findMany, findFirst, and findUnique with only false fields
  • Added test case for nested queries with only false fields in select

Example

// Before: SQL error
await db.user.findMany({ select: { id: false } });
// Error: near "from": syntax error

// After: Returns empty result
await db.user.findMany({ select: { id: false } });     // []
await db.user.findFirst({ select: { id: false } });    // null
await db.user.findUnique({ 
  where: { id: '1' }, 
  select: { id: false } 
});  // null

// Nested queries also work correctly
await db.user.findUnique({
  where: { id: '1' },
  select: {
    id: true,
    email: true,
    posts: { select: { id: false } }
  }
});  // { id: '1', email: 'test@test.com', posts: [] }
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: Query failed if there is only false field in the select params</issue_title>
<issue_description>The below code will show error:

    await db.user.findMany({
      select: {
        id: false,
      },
    }),
    reason: 'db-query-error',
    model: undefined,
    dbErrorCode: 'SQLITE_ERROR',
    dbErrorMessage: 'near "from": syntax error',
    rejectedByPolicyReason: undefined,
    sql: 'select from "User" ',

It generate a select statement without any field to be selected which cause the SQL error. </issue_description>

<agent_instructions>In this case direclty return an empty object</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 6, 2026 03:17
Co-authored-by: jiashengguo <16688722+jiashengguo@users.noreply.github.com>
Co-authored-by: jiashengguo <16688722+jiashengguo@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix query failure on empty select parameters Fix SQL syntax error when select contains only false fields Feb 6, 2026
Copilot AI requested a review from jiashengguo February 6, 2026 03:24
@jiashengguo jiashengguo marked this pull request as ready for review February 6, 2026 04:00
Copilot AI review requested due to automatic review settings February 6, 2026 04:00
@jiashengguo jiashengguo marked this pull request as draft February 6, 2026 04:01
select: { id: false } as any,
});
expect(r3).toBeNull();
});
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor

Copilot AI left a 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, and findUnique operations 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.

Copilot AI and others added 2 commits February 6, 2026 04:10
Co-authored-by: jiashengguo <16688722+jiashengguo@users.noreply.github.com>
Co-authored-by: jiashengguo <16688722+jiashengguo@users.noreply.github.com>
@jiashengguo jiashengguo requested a review from ymc9 February 6, 2026 04:14
Copilot AI changed the title Fix SQL syntax error when select contains only false fields Fix SQL syntax error when select contains only false fields (including nested queries) Feb 6, 2026
Copilot AI requested a review from jiashengguo February 6, 2026 04:14
@ymc9
Copy link
Member

ymc9 commented Feb 6, 2026

@copilot could you check Prisma ORM's behavior for this usage? For both top-level select and nested relation select.

Copy link
Contributor Author

Copilot AI commented Feb 6, 2026

@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:

  • Top-level select: Throws validation error: "The select statement for type X needs at least one truthy value"
  • Nested relation select: Same error for the nested relation: "The select statement for type Post needs at least one truthy value"

Current implementation (this PR):

  • Top-level select: Returns empty array for findMany, null for findFirst/findUnique
  • Nested relation select: Returns empty array for relation fields

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:

  • checkpoint.prisma.io
    • Triggering command: /opt/hostedtoolcache/node/24.13.0/x64/bin/node /opt/hostedtoolcache/node/24.13.0/x64/bin/node /tmp/prisma-test/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;7.3.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-02-06T04:49:28Z&#34;,&#34;project_hash&#34;:&#34;6fb518bd&#34;,&#34;cli_path&#34;:&#34;/tmp/prisma-test/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;6f2b06e8&#34;,&#34;endpoint&#34;:&#34;https://chec (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.13.0/x64/bin/node /opt/hostedtoolcache/node/24.13.0/x64/bin/node /tmp/prisma-test/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;7.3.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-02-06T04:49:34Z&#34;,&#34;project_hash&#34;:&#34;6fb518bd&#34;,&#34;cli_path&#34;:&#34;/tmp/prisma-test/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;6f2b06e8&#34;,&#34;endpoint&#34;:&#34;https://chec (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.13.0/x64/bin/node /opt/hostedtoolcache/node/24.13.0/x64/bin/node /tmp/prisma-test/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;7.3.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-02-06T04:49:47Z&#34;,&#34;project_hash&#34;:&#34;6fb518bd&#34;,&#34;cli_path&#34;:&#34;/tmp/prisma-test/node_modules/.bin/prisma&#34;,&#34;cli_path_hash&#34;:&#34;6f2b06e8&#34;,&#34;endpoint&#34;:&#34;https://chec (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Query failed if there is only false field in the select params

3 participants