Repository navigation
findUniqueOrThrow returns undefined after first error in same "tick" #29638
Description
Bug description
When calling findUniqueOrThrow many times in the same "tick", return values after the "first" thrown error instead return undefined. If only one fails, it works as expected. Only subsequent failures return undefined, breaking type safety and the expectation of the ...OrThrow function.
Severity
Reproduction
Node >= 24
pnpm
pnpm installpnpm run prisma generatedocker compose -f dev.compose.yaml up(or any local postgres 18, haven't tested other drivers)- Set DATABASE_URL (see dev.compose.yaml) in .env or as normal variable
pnpm run prisma migrate devnode --env-file-if-exists=.env main.ts
Expected vs. Actual Behavior
I expect all failed calls to throw and never return anything but a valid instance object. Instead I get undefined were the type-system claims undefined should be impossible, causing cascading issues when the undefined return value is used (potentially after other operations that were supposed to be "gated" by the existence of the object in the database)
Frequency
Consistently reproducible
Does this occur in development or production?
Both development and production
Is this a regression?
Issue present from 7.0.0 to 7.8.0
Workaround
Using findUnique and manually checking for null works as null is in either case. This requires chasing down all uses of ...OrThrow and replacing it with manual null checks
Prisma Schema & Queries
model User {
id String @id @default(cuid())
chatUsers ChatUser[]
}
model ChatUser {
chatId String
userId String
chat Chat @relation(fields: [chatId], references: [id])
user User @relation(fields: [userId], references: [id])
@@id([chatId, userId])
}
model Chat {
id String @id @default(cuid())
chatUsers ChatUser[]
} const userIds = ["bob", "eve", "alice", "david", "charlie"];
const chatId = "chat-id";
await client.user.createMany({ data: userIds.map((id) => ({ id })) });
await client.chat.create({ data: { id: chatId } });
await client.chatUser.createMany({
data: [
{ chatId, userId: userIds[0] },
{ chatId, userId: userIds[1] },
],
});
// Run many findUniqueOrThrow in the same "tick" with some failing
const results = await Promise.allSettled(
userIds.map((userId) =>
client.chat.findUniqueOrThrow({
where: {
id: chatId,
// Filter by existance of relation (this is what the original application did)
chatUsers: { some: { userId } },
},
}),
),
);
console.log(results);
/*
[
{ status: 'fulfilled', value: { id: 'bob' } },
{ status: 'fulfilled', value: { id: 'eve' } },
{
status: 'rejected',
reason: PrismaClientKnownRequestError:
Invalid `prisma.chat.findUniqueOrThrow()` invocation:
An operation failed because it depends on one or more records that were required but not found. No record was found for a query.
at zr.handleRequestError (REDACTED/node_modules/.pnpm/@prisma[email protected][email protected]_@[email protected][email protected][email protected][email protected]_/node_modules/@prisma/client/runtime/client.js:65:8286)
at zr.handleAndLogRequestError (REDACTED/node_modules/.pnpm/@[email protected][email protected]_@[email protected][email protected][email protected][email protected]_/node_modules/@prisma/client/runtime/client.js:65:7581)
at zr.request (REDACTED/node_modules/.pnpm/@[email protected][email protected]_@[email protected][email protected][email protected][email protected]_/node_modules/@prisma/client/runtime/client.js:65:7288)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
at async a (REDACTED/node_modules/.pnpm/@[email protected][email protected]_@[email protected][email protected][email protected][email protected]_/node_modules/@prisma/client/runtime/client.js:75:6862)
at async Promise.allSettled (index 2)
at async file:///REDACTED/main.ts:44:19 {
code: 'P2025',
meta: [Object],
clientVersion: '7.8.0'
}
},
{ status: 'fulfilled', value: undefined },
{ status: 'fulfilled', value: undefined }
]
*/Prisma Config
This is the default config from prisma init
// This file was generated by Prisma, and assumes you have installed the following:
// npm install --save-dev prisma dotenv
import "dotenv/config";
import { defineConfig } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
},
datasource: {
url: process.env["DATABASE_URL"],
},
});Logs & Debug Info
This includes the clearing and seeding of the demo. Only the findUniqueOrThrow calls should be of interest
Full DEBUG="*" output
prisma:client clientVersion 7.8.0 +3ms
prisma:client:clientEngine Using driver adapter: '{\n' +
' "provider": "postgres",\n' +
' "adapterName": "@prisma/adapter-pg",\n' +
' "config": {\n' +
' "connectionString": "postgresql://postgres:password@localhost:15432/postgres"\n' +
' },\n' +
' "externalPool": null\n' +
'}' +0ms
prisma:client Prisma Client call: +2ms
prisma:client prisma.chatUser.deleteMany() +0ms
prisma:client Generated request: +0ms
prisma:client {
"modelName": "ChatUser",
"action": "deleteMany",
"query": {
"arguments": {},
"selection": {
"$composites": true,
"$scalars": true
}
}
}
+0ms
prisma:client:clientEngine sending request +0ms
prisma:client:clientEngine query plan cache miss +22ms
prisma:client:clientEngine query plan created {
"type": "dataMap",
"args": {
"expr": {
"type": "execute",
"args": {
"type": "templateSql",
"fragments": [
{
"type": "stringChunk",
"chunk": "DELETE FROM \"public\".\"ChatUser\" WHERE 1=1"
}
],
"args": [],
"argTypes": [],
"placeholderFormat": {
"prefix": "$",
"hasNumbering": true
},
"chunkable": true
}
},
"structure": {
"type": "affectedRows"
},
"enums": {}
}
} +7ms
prisma:driver-adapter:pg [js::execute_raw] '{\n' +
' "sql": "DELETE FROM \\"public\\".\\"ChatUser\\" WHERE 1=1",\n' +
' "args": [],\n' +
' "argTypes": []\n' +
'}' +44ms
prisma:client:clientEngine query plan executed +20ms
prisma:client Prisma Client call: +0ms
prisma:client prisma.user.deleteMany() +0ms
prisma:client Generated request: +0ms
prisma:client {
"modelName": "User",
"action": "deleteMany",
"query": {
"arguments": {},
"selection": {
"$composites": true,
"$scalars": true
}
}
}
+0ms
prisma:client:clientEngine sending request +0ms
prisma:client:clientEngine query plan cache miss +1ms
prisma:client:clientEngine query plan created { "type": "dataMap", "args": { "expr": {
"type": "execute",
"args": {
"type": "templateSql",
"fragments": [
{
"type": "stringChunk",
"chunk": "DELETE FROM \"public\".\"User\" WHERE 1=1"
}
],
"args": [],
"argTypes": [],
"placeholderFormat": {
"prefix": "$",
"hasNumbering": true
},
"chunkable": true
}
},
"structure": {
"type": "affectedRows"
},
"enums": {}
}
} +0ms
prisma:driver-adapter:pg [js::execute_raw] '{\n' +
' "sql": "DELETE FROM \\"public\\".\\"User\\" WHERE 1=1",\n' +
' "args": [],\n' +
' "argTypes": []\n' +
'}' +21ms
prisma:client:clientEngine query plan executed +1ms
prisma:client Prisma Client call: +0ms
prisma:client prisma.chat.deleteMany() +0ms
prisma:client Generated request: +0ms
prisma:client {
"modelName": "Chat",
"action": "deleteMany",
"query": {
"arguments": {},
"selection": {
"$composites": true,
"$scalars": true
}
}
}
+0ms
prisma:client:clientEngine sending request +0ms
prisma:client:clientEngine query plan cache miss +0ms
prisma:client:clientEngine query plan created {
"type": "dataMap",
"args": {
"expr": {
"type": "execute",
"args": {
"type": "templateSql",
"fragments": [
{
"type": "stringChunk",
"chunk": "DELETE FROM \"public\".\"Chat\" WHERE 1=1"
}
],
"args": [],
"argTypes": [],
"placeholderFormat": {
"prefix": "$",
"hasNumbering": true
},
"chunkable": true
}
},
"structure": {
"type": "affectedRows"
},
"enums": {}
}
} +0ms
prisma:driver-adapter:pg [js::execute_raw] '{\n' +
' "sql": "DELETE FROM \\"public\\".\\"Chat\\" WHERE 1=1",\n' +
' "args": [],\n' +
' "argTypes": []\n' +
'}' +1ms
prisma:client:clientEngine query plan executed +1ms
prisma:client Prisma Client call: +1ms
prisma:client prisma.user.createMany({
data: [
{
id: "bob"
},
{
id: "eve"
},
{
id: "alice"
},
{
id: "david"
},
{
id: "charlie"
}
]
}) +0ms
prisma:client Generated request: +0ms
prisma:client {
"modelName": "User",
"action": "createMany",
"query": {
"arguments": {
"data": [
{
"id": "bob"
},
{
"id": "eve"
},
{
"id": "alice"
},
{
"id": "david"
},
{
"id": "charlie"
}
]
},
"selection": {
"$composites": true,
"$scalars": true
}
}
}
+0ms
prisma:client:clientEngine sending request +0ms
prisma:client:clientEngine query plan cache miss +0ms
prisma:client:clientEngine query plan created {
"type": "transaction",
"args": {
"type": "dataMap",
"args": {
"expr": {
"type": "execute",
"args": {
"type": "templateSql",
"fragments": [
{
"type": "stringChunk",
"chunk": "INSERT INTO \"public\".\"User\" (\"id\") VALUES ("
},
{
"type": "parameter"
},
{
"type": "stringChunk",
"chunk": "), ("
},
{
"type": "parameter"
},
{
"type": "stringChunk",
"chunk": "), ("
},
{
"type": "parameter"
},
{
"type": "stringChunk",
"chunk": "), ("
},
{
"type": "parameter"
},
{
"type": "stringChunk",
"chunk": "), ("
},
{
"type": "parameter"
},
{
"type": "stringChunk",
"chunk": ")"
}
],
"args": [
{
"prisma__type": "param",
"prisma__value": {
"name": "%1",
"type": "String"
}
},
{
"prisma__type": "param",
"prisma__value": {
"name": "%2",
"type": "String"
}
},
{
"prisma__type": "param",
"prisma__value": {
"name": "%3",
"type": "String"
}
},
{
"prisma__type": "param",
"prisma__value": {
"name": "%4",
"type": "String"
}
},
{
"prisma__type": "param",
"prisma__value": {
"name": "%5",
"type": "String"
}
}
],
"argTypes": [
{
"arity": "scalar",
"scalarType": "string",
"dbType": "TEXT"
},
{
"arity": "scalar",
"scalarType": "string",
"dbType": "TEXT"
},
{
"arity": "scalar",
"scalarType": "string",
"dbType": "TEXT"
},
{
"arity": "scalar",
"scalarType": "string",
"dbType": "TEXT"
},
{
"arity": "scalar",
"scalarType": "string",
"dbType": "TEXT"
}
],
"placeholderFormat": {
"prefix": "$",
"hasNumbering": true
},
"chunkable": true
}
},
"structure": {
"type": "affectedRows"
},
"enums": {}
}
}
} +5ms
prisma:driver-adapter:pg [js::startTransaction] options: '{\n "usePhantomQuery": false\n}' +7ms
prisma:driver-adapter:pg [js::execute_raw] '{\n "sql": "BEGIN",\n "args": [],\n "argTypes": []\n}' +1ms
prisma:driver-adapter:pg [js::execute_raw] '{\n' +
' "sql": "INSERT INTO \\"public\\".\\"User\\" (\\"id\\") VALUES ($1), ($2), ($3), ($4), ($5)",\n' +
' "args": [\n' +
' "bob",\n' +
' "eve",\n' +
' "alice",\n' +
' "david",\n' +
' "charlie"\n' +
' ],\n' +
' "argTypes": [\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "string",\n' +
' "dbType": "TEXT"\n' +
' },\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "string",\n' +
' "dbType": "TEXT"\n' +
' },\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "string",\n' +
' "dbType": "TEXT"\n' +
' },\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "string",\n' +
' "dbType": "TEXT"\n' +
' },\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "string",\n' +
' "dbType": "TEXT"\n' +
' }\n' +
' ]\n' +
'}' +0ms
prisma:client:transactionManager Closing transaction. {
"transactionId": "72c6cf3e-601b-4876-ac67-8437fd61d40b",
"status": "committed"
} +2ms
prisma:driver-adapter:pg [js::execute_raw] '{\n "sql": "COMMIT",\n "args": [],\n "argTypes": []\n}' +1ms
prisma:driver-adapter:pg [js::commit] +1ms
prisma:client:clientEngine query plan executed +1ms
prisma:client Prisma Client call: +0ms
prisma:client prisma.chat.create({
data: {
id: "chat-id"
}
}) +0ms
prisma:client Generated request: +0ms
prisma:client {
"modelName": "Chat",
"action": "createOne",
"query": {
"arguments": {
"data": {
"id": "chat-id"
}
},
"selection": {
"$composites": true,
"$scalars": true
}
}
}
+0ms
prisma:client:clientEngine sending request +0ms
prisma:client:clientEngine query plan cache miss +0ms
prisma:client:clientEngine query plan created {
"type": "dataMap",
"args": {
"expr": {
"type": "unique",
"args": {
"type": "query",
"args": {
"type": "templateSql",
"fragments": [
{
"type": "stringChunk",
"chunk": "INSERT INTO \"public\".\"Chat\" (\"id\") VALUES ("
},
{
"type": "parameter"
},
{
"type": "stringChunk",
"chunk": ") RETURNING \"public\".\"Chat\".\"id\""
}
],
"args": [
{
"prisma__type": "param",
"prisma__value": {
"name": "%1",
"type": "String"
}
}
],
"argTypes": [
{
"arity": "scalar",
"scalarType": "string",
"dbType": "TEXT"
}
],
"placeholderFormat": {
"prefix": "$",
"hasNumbering": true
},
"chunkable": true
}
}
},
"structure": {
"type": "object",
"serializedName": null,
"fields": {
"id": {
"type": "field",
"dbName": "id",
"fieldType": {
"arity": "required",
"type": "string"
}
}
},
"skipNulls": false
},
"enums": {}
}
} +2ms
prisma:driver-adapter:pg [js::query_raw] '{\n' +
' "sql": "INSERT INTO \\"public\\".\\"Chat\\" (\\"id\\") VALUES ($1) RETURNING \\"public\\".\\"Chat\\".\\"id\\"",\n' +
' "args": [\n' +
' "chat-id"\n' +
' ],\n' +
' "argTypes": [\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "string",\n' +
' "dbType": "TEXT"\n' +
' }\n' +
' ]\n' +
'}' +2ms
prisma:client:clientEngine query plan executed +1ms
prisma:client Prisma Client call: +1ms
prisma:client prisma.chatUser.createMany({
data: [
{
chatId: "chat-id",
userId: "bob"
},
{
chatId: "chat-id",
userId: "eve"
}
]
}) +0ms
prisma:client Generated request: +0ms
prisma:client {
"modelName": "ChatUser",
"action": "createMany",
"query": {
"arguments": {
"data": [
{
"chatId": "chat-id",
"userId": "bob"
},
{
"chatId": "chat-id",
"userId": "eve"
}
]
},
"selection": {
"$composites": true,
"$scalars": true
}
}
}
+0ms
prisma:client:clientEngine sending request +0ms
prisma:client:clientEngine query plan cache miss +0ms
prisma:client:clientEngine query plan created {
"type": "transaction",
"args": {
"type": "dataMap",
"args": {
"expr": {
"type": "execute",
"args": {
"type": "templateSql",
"fragments": [
{
"type": "stringChunk",
"chunk": "INSERT INTO \"public\".\"ChatUser\" (\"chatId\",\"userId\") VALUES ("
},
{
"type": "parameter"
},
{
"type": "stringChunk",
"chunk": ","
},
{
"type": "parameter"
},
{
"type": "stringChunk",
"chunk": "), ("
},
{
"type": "parameter"
},
{
"type": "stringChunk",
"chunk": ","
},
{
"type": "parameter"
},
{
"type": "stringChunk",
"chunk": ")"
}
],
"args": [
{
"prisma__type": "param",
"prisma__value": {
"name": "%1",
"type": "String"
}
},
{
"prisma__type": "param",
"prisma__value": {
"name": "%2",
"type": "String"
}
},
{
"prisma__type": "param",
"prisma__value": {
"name": "%1",
"type": "String"
}
},
{
"prisma__type": "param",
"prisma__value": {
"name": "%3",
"type": "String"
}
}
],
"argTypes": [
{
"arity": "scalar",
"scalarType": "string",
"dbType": "TEXT"
},
{
"arity": "scalar",
"scalarType": "string",
"dbType": "TEXT"
},
{
"arity": "scalar",
"scalarType": "string",
"dbType": "TEXT"
},
{
"arity": "scalar",
"scalarType": "string",
"dbType": "TEXT"
}
],
"placeholderFormat": {
"prefix": "$",
"hasNumbering": true
},
"chunkable": true
}
},
"structure": {
"type": "affectedRows"
},
"enums": {}
}
}
} +0ms
prisma:driver-adapter:pg [js::startTransaction] options: '{\n "usePhantomQuery": false\n}' +2ms
prisma:driver-adapter:pg [js::execute_raw] '{\n "sql": "BEGIN",\n "args": [],\n "argTypes": []\n}' +0ms
prisma:driver-adapter:pg [js::execute_raw] '{\n' +
' "sql": "INSERT INTO \\"public\\".\\"ChatUser\\" (\\"chatId\\",\\"userId\\") VALUES ($1,$2), ($3,$4)",\n' +
' "args": [\n' +
' "chat-id",\n' +
' "bob",\n' +
' "chat-id",\n' +
' "eve"\n' +
' ],\n' +
' "argTypes": [\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "string",\n' +
' "dbType": "TEXT"\n' +
' },\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "string",\n' +
' "dbType": "TEXT"\n' +
' },\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "string",\n' +
' "dbType": "TEXT"\n' +
' },\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "string",\n' +
' "dbType": "TEXT"\n' +
' }\n' +
' ]\n' +
'}' +0ms
prisma:client:transactionManager Closing transaction. {
"transactionId": "3da9d2ef-ca44-4dae-af74-6c91b034a0da",
"status": "committed"
} +1ms
prisma:driver-adapter:pg [js::execute_raw] '{\n "sql": "COMMIT",\n "args": [],\n "argTypes": []\n}' +1ms
prisma:driver-adapter:pg [js::commit] +1ms
prisma:client:clientEngine query plan executed +1ms
prisma:client Prisma Client call: +0ms
prisma:client prisma.chat.findUniqueOrThrow({
where: {
id: "chat-id",
chatUsers: {
some: {
userId: "bob"
}
}
}
}) +1ms
prisma:client Generated request: +0ms
prisma:client {
"modelName": "Chat",
"action": "findUniqueOrThrow",
"query": {
"arguments": {
"where": {
"id": "chat-id",
"chatUsers": {
"some": {
"userId": "bob"
}
}
}
},
"selection": {
"$composites": true,
"$scalars": true
}
}
}
+0ms
prisma:client Prisma Client call: +0ms
prisma:client prisma.chat.findUniqueOrThrow({
where: {
id: "chat-id",
chatUsers: {
some: {
userId: "eve"
}
}
}
}) +0ms
prisma:client Generated request: +0ms
prisma:client {
"modelName": "Chat",
"action": "findUniqueOrThrow",
"query": {
"arguments": {
"where": {
"id": "chat-id",
"chatUsers": {
"some": {
"userId": "eve"
}
}
}
},
"selection": {
"$composites": true,
"$scalars": true
}
}
}
+0ms
prisma:client Prisma Client call: +0ms
prisma:client prisma.chat.findUniqueOrThrow({
where: {
id: "chat-id",
chatUsers: {
some: {
userId: "alice"
}
}
}
}) +0ms
prisma:client Generated request: +0ms
prisma:client {
"modelName": "Chat",
"action": "findUniqueOrThrow",
"query": {
"arguments": {
"where": {
"id": "chat-id",
"chatUsers": {
"some": {
"userId": "alice"
}
}
}
},
"selection": {
"$composites": true,
"$scalars": true
}
}
}
+0ms
prisma:client Prisma Client call: +0ms
prisma:client prisma.chat.findUniqueOrThrow({
where: {
id: "chat-id",
chatUsers: {
some: {
userId: "david"
}
}
}
}) +0ms
prisma:client Generated request: +0ms
prisma:client {
"modelName": "Chat",
"action": "findUniqueOrThrow",
"query": {
"arguments": {
"where": {
"id": "chat-id",
"chatUsers": {
"some": {
"userId": "david"
}
}
}
},
"selection": {
"$composites": true,
"$scalars": true
}
}
}
+0ms
prisma:client Prisma Client call: +0ms
prisma:client prisma.chat.findUniqueOrThrow({
where: {
id: "chat-id",
chatUsers: {
some: {
userId: "charlie"
}
}
}
}) +0ms
prisma:client Generated request: +0ms
prisma:client {
"modelName": "Chat",
"action": "findUniqueOrThrow",
"query": {
"arguments": {
"where": {
"id": "chat-id",
"chatUsers": {
"some": {
"userId": "charlie"
}
}
}
},
"selection": {
"$composites": true,
"$scalars": true
}
}
}
+0ms
prisma:client:clientEngine batch query plan cache miss +0ms
prisma:driver-adapter:pg [js::startTransaction] options: '{\n "usePhantomQuery": false\n}' +7ms
prisma:driver-adapter:pg [js::execute_raw] '{\n "sql": "BEGIN",\n "args": [],\n "argTypes": []\n}' +0ms
prisma:driver-adapter:pg [js::query_raw] '{\n' +
' "sql": "SELECT \\"public\\".\\"Chat\\".\\"id\\" FROM \\"public\\".\\"Chat\\" WHERE (\\"public\\".\\"Chat\\".\\"id\\" = $1 AND EXISTS(SELECT \\"t0\\".\\"chatId\\" FROM \\"public\\".\\"ChatUser\\" AS \\"t0\\" WHERE (\\"t0\\".\\"userId\\" = $2 AND (\\"public\\".\\"Chat\\".\\"id\\") = (\\"t0\\".\\"chatId\\") AND \\"t0\\".\\"chatId\\" IS NOT NULL))) LIMIT $3 OFFSET $4",\n' +
' "args": [\n' +
' "chat-id",\n' +
' "bob",\n' +
' "1",\n' +
' "0"\n' +
' ],\n' +
' "argTypes": [\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "string",\n' +
' "dbType": "TEXT"\n' +
' },\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "string",\n' +
' "dbType": "TEXT"\n' +
' },\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "bigint",\n' +
' "dbType": null\n' +
' },\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "bigint",\n' +
' "dbType": null\n' +
' }\n' +
' ]\n' +
'}' +1ms
prisma:driver-adapter:pg [js::query_raw] '{\n' +
' "sql": "SELECT \\"public\\".\\"Chat\\".\\"id\\" FROM \\"public\\".\\"Chat\\" WHERE (\\"public\\".\\"Chat\\".\\"id\\" = $1 AND EXISTS(SELECT \\"t0\\".\\"chatId\\" FROM \\"public\\".\\"ChatUser\\" AS \\"t0\\" WHERE (\\"t0\\".\\"userId\\" = $2 AND (\\"public\\".\\"Chat\\".\\"id\\") = (\\"t0\\".\\"chatId\\") AND \\"t0\\".\\"chatId\\" IS NOT NULL))) LIMIT $3 OFFSET $4",\n' +
' "args": [\n' +
' "chat-id",\n' +
' "eve",\n' +
' "1",\n' +
' "0"\n' +
' ],\n' +
' "argTypes": [\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "string",\n' +
' "dbType": "TEXT"\n' +
' },\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "string",\n' +
' "dbType": "TEXT"\n' +
' },\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "bigint",\n' +
' "dbType": null\n' +
' },\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "bigint",\n' +
' "dbType": null\n' +
' }\n' +
' ]\n' +
'}' +0ms
prisma:driver-adapter:pg [js::query_raw] '{\n' +
' "sql": "SELECT \\"public\\".\\"Chat\\".\\"id\\" FROM \\"public\\".\\"Chat\\" WHERE (\\"public\\".\\"Chat\\".\\"id\\" = $1 AND EXISTS(SELECT \\"t0\\".\\"chatId\\" FROM \\"public\\".\\"ChatUser\\" AS \\"t0\\" WHERE (\\"t0\\".\\"userId\\" = $2 AND (\\"public\\".\\"Chat\\".\\"id\\") = (\\"t0\\".\\"chatId\\") AND \\"t0\\".\\"chatId\\" IS NOT NULL))) LIMIT $3 OFFSET $4",\n' +
' "args": [\n' +
' "chat-id",\n' +
' "alice",\n' +
' "1",\n' +
' "0"\n' +
' ],\n' +
' "argTypes": [\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "string",\n' +
' "dbType": "TEXT"\n' +
' },\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "string",\n' +
' "dbType": "TEXT"\n' +
' },\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "bigint",\n' +
' "dbType": null\n' +
' },\n' +
' {\n' +
' "arity": "scalar",\n' +
' "scalarType": "bigint",\n' +
' "dbType": null\n' +
' }\n' +
' ]\n' +
'}' +1ms
prisma:client:transactionManager Closing transaction. {
"transactionId": "ca229d4c-e8a9-4603-a2fb-80d0b5233aab",
"status": "rolled_back"
} +8ms
prisma:driver-adapter:pg [js::execute_raw] '{\n "sql": "ROLLBACK",\n "args": [],\n "argTypes": []\n}' +0ms
prisma:driver-adapter:pg [js::rollback] +0ms
prisma:client:request_handler {
"name": "UserFacingError",
"code": "P2025",
"meta": {
"operation": "a query"
}
} +0ms
Environment & Setup
- OS: NixOS
- Database: PostgreSQL 18
- Node.js version: v24.14.1
Prisma Version
Loaded Prisma config from prisma.config.ts.
Prisma schema loaded from prisma/schema.prisma.
prisma : 7.8.0
@prisma/client : 7.8.0
Operating System : linux
Architecture : x64
Node.js : v24.14.1
TypeScript : unknown
Query Compiler : enabled
PSL : @prisma/prisma-schema-wasm 7.8.0-6.3c6e192761c0362d496ed980de936e2f3cebcd3a
Schema Engine : schema-engine-cli 0000000000000000000000000000000000000000 (at ../../../../nix/store/aq4pd0qb4hg030309mi356h060mjnqj9-prisma-engines_7-7.8.0/bin/schema-engine, resolved by PRISMA_SCHEMA_ENGINE_BINARY)
Default Engines Hash : 3c6e192761c0362d496ed980de936e2f3cebcd3a
Studio : 0.27.3
Preview Features : views
Activity
Shgit29 commentedon Jun 20, 2026
@RedPhoenixQ
I was able to reproduce this consistently.
Environment:
Observed with concurrent
Promise.allSettledcalls:{ id: 'chat-id' }P2025undefinedObserved output pattern:
fulfilled -> { id: 'chat-id' } fulfilled -> { id: 'chat-id' } rejected -> P2025 fulfilled -> undefined fulfilled -> undefinedI also tested sequential
findUniqueOrThrowcalls with the same query and data. In that case, all missing records reject correctly withP2025:I also tested
findUniquein the concurrentPromise.allSettledcase. It returnsnullcorrectly for the missing records:fulfilled -> { id: 'chat-id' } fulfilled -> { id: 'chat-id' } fulfilled -> null fulfilled -> null fulfilled -> nullSo from what I can see, the issue seems specific to the concurrent/batched
findUniqueOrThrowpath. I’m checking whether this can be covered with a regression test in the Prisma Client test suite.Shgit29 commentedon Jun 24, 2026
@RedPhoenixQ
I was able to reproduce this and added a functional regression test.
The issue seems to happen in the ClientEngine multi-batch path: after the first
findUniqueOrThrow()miss, the batch loop stops early, so fewer results are returned than requests. That causes the later DataLoader slots to resolve asundefined.I have a small fix that keeps collecting results for auto-batched
findUnique/findUniqueOrThrowreads outside explicit batch transactions. The targeted regression test passes locally with:pnpm --filter @prisma/client test:functional:code --adapter js_pg --runInBand 29638-concurrent-find-unique-or-throw
I’ll open a PR for this.
Shgit29 commentedon Jun 26, 2026
Hi @RedPhoenixQ , I opened a PR for this issue here: #29654
It adds a regression test for the concurrent
findUniqueOrThrow()case and keeps the fix scoped to the Prisma Client batch path.RedPhoenixQ commentedon Jun 26, 2026
@Shgit29 Thank you for taking the time to look into this and submitting a fix. Much appreciated
fix(client): handle batched findUniqueOrThrow misses (prisma#29654)
fix(client): handle batched findUniqueOrThrow misses (prisma#29654)