-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.Bug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.A reported bug.topic: queryCompiler
Description
Bug description
Count relations does not work with the new queryCompiler
feature enabled.
This does not affect the db.user.count()
which works as expected.
Severity
🚨 Critical: Data loss, app crash, security issue
Reproduction
https://github.com/hrougier/prisma-query-compiler-count-issue
Expected vs. Actual Behavior
I expect the _count
property to have a value.
Frequency
Consistently reproducible
Does this occur in development or production?
Both development and production
Is this a regression?
No, it's still a preview feature
Workaround
Remove the queryCompiler
feature flag, run prisma generate
again and now it works:
[
{
"id": 1,
"name": "Alice",
"_count": {
"posts": 2
}
},
{
"id": 2,
"name": "Bob",
"_count": {
"posts": 1
}
}
]
Prisma Schema & Queries
Using the queryCompiler
preview feature in schema.prisma
generator client {
provider = "prisma-client"
output = "./generated"
moduleFormat = "esm"
previewFeatures = ["driverAdapters", "queryCompiler"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
authorId Int
author User @relation(fields: [authorId], references: [id])
}
and counting relations between User
and Post
:
await prisma.user.findMany({
select: {
id: true,
name: true,
_count: {
select: {
posts: true,
},
},
}
// same issue using:
// include: {
// _count: {
// select: { posts: true },
// },
// },
})
returns nothing for the _count
property:
[
{
"id": 1,
"name": "Alice"
},
{
"id": 2,
"name": "Bob"
}
]
Prisma Config
// Add your `prisma.config.ts`
Logs & Debug Info
// Debug logs here
Environment & Setup
- OS: macOS
- Database: PostgreSQL
- Node.js version: v22.15.0
Prisma Version
prisma : 6.7.0
@prisma/client : 6.7.0
Computed binaryTarget : darwin-arm64
Operating System : darwin
Architecture : arm64
Node.js : v22.15.0
TypeScript : 5.8.3
Query Engine (Node-API) : libquery-engine 3cff47a7f5d65c3ea74883f1d736e41d68ce91ed (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine : schema-engine-cli 3cff47a7f5d65c3ea74883f1d736e41d68ce91ed (at node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm : @prisma/prisma-schema-wasm 6.7.0-36.3cff47a7f5d65c3ea74883f1d736e41d68ce91ed
Default Engines Hash : 3cff47a7f5d65c3ea74883f1d736e41d68ce91ed
Studio : 0.511.0
Preview Features : driverAdapters, queryCompiler
Suniron and yovanoc
Metadata
Metadata
Assignees
Labels
bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.Bug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.A reported bug.topic: queryCompiler