Find many returns empty array or null
See original GitHub issueBug description
FindMany query returns null or empty, if it uses where in query with 1000+ items. This bug can be seen in many-to-many and one to many nested models. Tested in Mysql-8 and MariaDB. (EDIT: It works with PostgreSQL)
How to reproduce
Seed and then, these queries returns empty array;
this.prisma.user.findMany({ include: { posts: true }})
this.prisma.post.findMany({ include: { users: true }})
this.prisma.user.findMany({ where: { id: { lt: 51}}, include: { posts: true }});
But interestingly this works. (I think the problem is the count of where in ids, 50 * 20 = 1000)
this.prisma.user.findMany({ where: { id: { lt: 50}}, include: { posts: true }});
Expected behavior
[ {
"id": 1,
"email": "tf2v9@mail.com",
"name": "9ev6v",
"posts": []
},
{
"id": 2,
"email": "5usm7@mail.com",
"name": "y3nbu",
"posts": []
},
{
"id": 3,
"email": "8qwpt@mail.com",
"name": "oqjec",
"posts": []
}]
[ {
"id": 1,
"title": "p70a3",
"content": "h5g7q@mail.com",
"published": false,
"users": []
},
{
"id": 2,
"title": "x3mg3",
"content": "gxc7z@mail.com",
"published": false,
"users": []
}]
Prisma information
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model User {
id Int @default(autoincrement()) @id
email String @unique
name String?
posts Post[]
}
model Post {
id Int @default(autoincrement()) @id
title String
content String?
published Boolean? @default(false)
users User[]
}
Environment & setup
- OS: Ubuntu 22.04
- Database: MariaDB
- Node.js version: 16.15
Prisma Version
4.0.0
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:11 (3 by maintainers)
Top Results From Across the Web
One To Many returns empty array - Stack Overflow
When I execute this code snippet and check to see the results, p1 has properly assigned w1 as the p1.Workplace, but the list...
Read more >Return an empty array or collection instead of a null
For methods that return a set of values using an array or collection, returning an empty array or collection is an excellent alternative...
Read more >Empty arrays and collections should be returned instead of null
Returning null instead of an actual array, collection or map forces callers of the method to explicitly test for nullity, making them more...
Read more >Check if an array is empty or not in JavaScript - GeeksforGeeks
The array can be checked if it is empty by using the array.length property. This property returns the number of elements in the...
Read more >empty - Manual - PHP
Returns true if var does not exist or has a value that is empty or equal to ... I normally count() an array,...
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
Closing this issue as it’s independent of Prisma: it’s instead related to a bug in some MariaDB versions. This reproduction runs test cases inspired by issue #14539 (which comprises #12338 and #14019 as well) on a “bugged” MariaDB instance (
mariadb:10.7.3
), on a “stable” MariaDB instance (mariadb:10.8.4
), and on a recent MySQL instance (mysql:8.0.30
).Thanks to @kkomelin and @HendrikJan for their independent reproductions, and to @d-Rickyy-b for spotting https://jira.mariadb.org/browse/MDEV-27937.
@aqrln if you need a playground for that, please use my https://github.com/kkomelin/prisma-in-issue-reproduction and just change the docker image to the one you need to test with.