The findMany query fails silently when the array length passed through IN parameter exceeds 999
See original GitHub issueBug description
The findMany query fails silently when the array length passed through IN parameter exceeds 999.
How to reproduce
const tags999 = await prisma.tag.findMany({
where: {
id: {
in: Array.from({length: 999}, () => Math.floor(Math.random() * 1000))
}
},
})
console.log(tags999)
// Returns [{obj1}, {obj2}, ....] which is correct.
const tags1000 = await prisma.tag.findMany({
where: {
id: {
in: Array.from({length: 1000}, () => Math.floor(Math.random() * 1000))
}
},
})
console.log(tags1000)
// Returns [] which is wrong.
// We need a proper error message here, something like "You have reached the max length of array passed to IN parameter."
A related bug occurs when we use relation queries with more than 1000 tags added to all posts in total:
const posts = await prisma.post.findMany({
include: {
postTags: {
include: {
tag: true
}
}
}
})
Which causes the following error:
Invalid
prisma.post.findMany()
invocation: Inconsistent query result: Field tag is required to return data, gotnull
instead.
It probably happens because the relation query somehow uses IN subquery. It’s my guess based on how this kind of relation query is implemented in another framework.
Expected behavior
Remove this hardcoded limit for < 1000 items in the IN array. Let user decide what’s safe for them!
Alternatively:
- The shown IN query with more than 1000 items passed should fail with a clear error message.
- The described relation query should produce a better error message.
Prisma information
model Post {
id Int @id @default(autoincrement()) @db.UnsignedInt
postTags PostTag[]
@@map("posts")
}
model Tag {
id Int @id @default(autoincrement()) @db.UnsignedInt
postTags PostTag[]
@@map("tags")
}
model PostTag {
postId Int @map("post_id") @db.UnsignedInt
tagId Int @map("tag_id") @db.UnsignedInt
post Post @relation(fields: [postId], references: [id], onDelete: Cascade)
tag Tag @relation(fields: [tagId], references: [id], onDelete: Cascade)
@@id([postId, tagId])
@@map("posts_tags")
}
Environment & setup
- OS: Docker: node:16-alpine (Linux)
- Database: Docker: mariadb:10.7
- Node.js version: v16.14.2
Prisma Version
"@prisma/client": "^4.1.1"
"prisma": "^4.1.1"
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:12 (4 by maintainers)
Top Results From Across the Web
prisma findmany where not null - You.com | The Search Engine You ...
Prisma findMany function is not returning relational data ... The findMany query fails silently when the array length passed through IN parameter exceeds...
Read more >Prisma 4.4.0 Release - GitClear
Ordered by the degree to which they evolved the repo in this version. ... The findMany query fails silently when the array length...
Read more >Cannot get the Length of an Array in an extra Function in C++
You cannot determine the length of an array that is passed to you like that. You need to also pass the length as...
Read more >Konstantin Komelin в LinkedIn: How to Protect Your CMS Site from ...
The findMany query fails silently when the array length passed through IN parameter exceeds 999 · Issue #14539 · prisma/prisma. github.com.
Read more >1177 Error: Operation name <name> exceeds maximum length.
Powered by Zoomin Software. For more details please contactZoomin · Rocket Software Documentation · Home · Library · Register · Login ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The worst things is you can’t expect that. You start working on your app and everything works perfectly. Data is displayed. Search filters are working. You happily deploy the app to production and sleep well… until one day everything breaks suddenly. The data is not on the screen anymore. And the logs are clean. The reason is trivial - when your database grows, IN select queries stop working… not all at once, just some of them in which IN array length exceeds 999. And tomorrow any other IN queries can gracefully return empty result.
No app should behave that unpredictably, so for me it’s a high priority.
Already. Thanks to your tests @jkomyno I have found the reason of the problem: https://github.com/prisma/prisma/pull/15124#issuecomment-1233913074