Running multiple findUnique's in parallel causes both to return null
See original GitHub issueBug description
When running two of the same findUnique queries in parallel, both return null where they should return the same document.
How to reproduce
- Create a new Prisma project with a PostgreSQL database.
- Add a table with a @@unique attribute
datasource db {
provider = "postgresql"
url = "URL"
}
generator client {
provider = "prisma-client-js"
}
model Property {
id String @id @default(cuid())
Availability Availability[]
}
model Availability {
date DateTime
property Property @relation(fields: [propertyId], references: [id])
propertyId String
status AvailabilityStatus @default(AVAILABLE)
@@unique([propertyId, date, status])
}
enum AvailabilityStatus {
AVAILABLE
}
- Create a new set of documents in the table
const property = await prisma.property.create({});
const targetDate = new Date('2020-12-03T00:00:00.000Z');
await prisma.availability.create({
data: {
property: { connect: {id: property.id }},
status: AvailabilityStatus.AVAILABLE,
date: targetDate,
},
});
- Query the document twice in parallel
const firstUnique = prisma.availability.findUnique({
where: {
propertyId_date_status: {
propertyId: property.id,
status: AvailabilityStatus.AVAILABLE,
date: targetDate,
}
},
});
const secondUnique = prisma.availability.findUnique({
where: {
propertyId_date_status: {
propertyId: property.id,
status: AvailabilityStatus.AVAILABLE,
date: targetDate,
}
},
});
const res = await Promise.all([firstUnique, secondUnique])
console.log(res); <-- [null, null]
Expected behavior
Expected to return the same document twice - a warning would also be super helpful if this happens.
Prisma information
Environment & setup
- OS: Mac
- Database: PostgreSQL
- Node.js version: 12.18.0
- Prisma version: 2.12.1
@prisma/cli : 2.12.1
@prisma/client : 2.12.1
Current platform : darwin
Query Engine : query-engine cf0680a1bfe8d5e743dc659cc7f08009f9587d58 (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine : migration-engine-cli cf0680a1bfe8d5e743dc659cc7f08009f9587d58 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core cf0680a1bfe8d5e743dc659cc7f08009f9587d58 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt cf0680a1bfe8d5e743dc659cc7f08009f9587d58 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Studio : 0.322.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
C# List.Find() inside Parallel.ForEach Sometimes Returns NULL
I know writing to a common variable from multiple threads is problematic (race conditions) but I can't see why reading from a common...
Read more >Data Loading - Remix
This can get a little tricky with React's controlled component concept. This is only needed if the search params can be set in...
Read more >Issues with NULL values in input columns in Parallel ... - IBM
To test if a value is NULL in a logical expression, use one of these two functions. IsNotNull(); IsNull(). For example: DSLink3.OrderCount +...
Read more >Null and undefined (Reference) - Prisma
When this query is run no data is returned. This is in contrast to the AND and NOT operators, which will both return...
Read more >Check if a Value Is Null or Undefined in JavaScript or Node.js
When „empty“ we mean that they don't have an exact value assigned. These two values are null and undefined . Both values, null...
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
We just run into this behavior and it was incredibly surprising. The most disappointing part is how how silent this error is. There is no warning in the prisma logs, nothing documented about using composite keys with findUnique not working when doing things in parallel. While I understand that this bug may be hard to resolve, at the very least some loud logging or just a panic so it can be caught quickly would be the least I would expect from a tool that should be prod-ready.
EDIT: In retrospect my comment comes accross a little too aggressive/accusatory, I apologize for my tone. Commenting after spending a long time debugging got the better of me.
I do see it fixed in 2.15! Thank you so much!
I should have tried updating my prisma before commenting, I was on 2.14 and since I didn’t see anything in the changelog for 2.15 about this I assumed it was still an issue 🤦🏽