Nonsense error on correctly structured query

Hi, I got this error in production complaining about values on a list for an "in" filter on a query:
PrismaClientValidationError:
Invalid `prisma.backOrderQueue.findMany()` invocation:

{
where: {
orgId: "org_2oRsfrtFV4WJMvC6lEOiVdufnrt",
sku: {
in: [
"107082002326",
"107082069120",
"109082004770",
"107082089847",
"107084003820",
"107082001513",
"107082001525",
"107082004860",
"107082022468",
"107082022469",
"107182137043",
"107082004816",
"107082004815",
"107082004861"
]
}
}
}

Argument `in`: Invalid value provided. Expected ListStringFieldRefInput, provided (Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null).
at An (/var/task/node_modules/@prisma/client/runtime/library.js:114:7526)
at _n.handleRequestError (/var/task/node_modules/@prisma/client/runtime/library.js:121:7392)
at _n.handleAndLogRequestError (/var/task/node_modules/@prisma/client/runtime/library.js:121:7057)
at _n.request (/var/task/node_modules/@prisma/client/runtime/library.js:121:6741)
at async Array.$allOperations (/var/task/.next/server/chunks/4499.js:38:691)
at async l (/var/task/node_modules/@prisma/client/runtime/library.js:130:9355)
at async j (/var/task/.next/server/app/api/inventory/order/[orderId]/route.js:1:5552)
at async Promise.all (index 0)
at async /var/task/.next/server/app/api/inventory/order/[orderId]/route.js:1:4824
at async Proxy._transactionWithCallback (/var/task/node_modules/@prisma/client/runtime/library.js:130:7722) {
clientVersion: '5.17.0'
}
PrismaClientValidationError:
Invalid `prisma.backOrderQueue.findMany()` invocation:

{
where: {
orgId: "org_2oRsfrtFV4WJMvC6lEOiVdufnrt",
sku: {
in: [
"107082002326",
"107082069120",
"109082004770",
"107082089847",
"107084003820",
"107082001513",
"107082001525",
"107082004860",
"107082022468",
"107082022469",
"107182137043",
"107082004816",
"107082004815",
"107082004861"
]
}
}
}

Argument `in`: Invalid value provided. Expected ListStringFieldRefInput, provided (Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null).
at An (/var/task/node_modules/@prisma/client/runtime/library.js:114:7526)
at _n.handleRequestError (/var/task/node_modules/@prisma/client/runtime/library.js:121:7392)
at _n.handleAndLogRequestError (/var/task/node_modules/@prisma/client/runtime/library.js:121:7057)
at _n.request (/var/task/node_modules/@prisma/client/runtime/library.js:121:6741)
at async Array.$allOperations (/var/task/.next/server/chunks/4499.js:38:691)
at async l (/var/task/node_modules/@prisma/client/runtime/library.js:130:9355)
at async j (/var/task/.next/server/app/api/inventory/order/[orderId]/route.js:1:5552)
at async Promise.all (index 0)
at async /var/task/.next/server/app/api/inventory/order/[orderId]/route.js:1:4824
at async Proxy._transactionWithCallback (/var/task/node_modules/@prisma/client/runtime/library.js:130:7722) {
clientVersion: '5.17.0'
}
The logged query shows that the query passed has a list of strings and not a list of nulls as suggested by the error message. Has anyone ever stumbled across this before? I'm unable to reproduce, as the same code runs normally. Bot conversation: https://discord.com/channels/937751382725886062/1319378542412300348
13 Replies
Nurul
Nurul•2mo ago
Hello @Giovani Granzotto 👋 If I understand correctly, you got this error once in your deployed application. And this error doesn't seem to happen in your local environment, correct?
Giovani Granzotto
Giovani GranzottoOP•2mo ago
Hi @Nurul . Yes, I got this error on my production deploy. I wasn't able to reproduce it either locally or in the deployed environment, it seemed like a one off or intermittent error, do you have any information on the conditions that could cause it?
Nurul
Nurul•2mo ago
I think you can add a condition to filter out nulls to prevent this situation from happening again
const sanitizedSku = sku.filter((item) => item != null);
const sanitizedSku = sku.filter((item) => item != null);
Can you examine different parts of your code that populate the sku array? Is there any conditional logic that might lead to null values being included?
Giovani Granzotto
Giovani GranzottoOP•2mo ago
Hi @Nurul . This does not work, as a developer added this filter a few days ago when he saw the error and it happened again now. Also, why would the library log the query with a non null string if it was passed as null?
PrismaClientValidationError:
Invalid `prisma.backOrderQueue.findMany()` invocation:

{
where: {
orgId: "org_2p02m0j784obFqd5TJzIAcVwHzN",
sku: {
in: [
"207082011377"
]
}
}
}

Argument `in`: Invalid value provided. Expected ListStringFieldRefInput, provided (Null).
PrismaClientValidationError:
Invalid `prisma.backOrderQueue.findMany()` invocation:

{
where: {
orgId: "org_2p02m0j784obFqd5TJzIAcVwHzN",
sku: {
in: [
"207082011377"
]
}
}
}

Argument `in`: Invalid value provided. Expected ListStringFieldRefInput, provided (Null).
This is the whole function code. I thought it might have something to do with closures and the strings getting garbage collected or something else low-level like that, but it still doesn't make sense
const getBackorderQuantities = async (
items: { sku: string }[],
orgId: string,
prisma: Prisma.DefaultPrismaClient,
): Promise<Record<string, BackOrderQueue | undefined>> => {
const skus = items.map((i) => i.sku).filter((sku) => sku !== null);
return buildIdentityMap(
await prisma.backOrderQueue.findMany({
where: { orgId, sku: { in: skus } },
}),
(i) => i.sku,
);
};
const getBackorderQuantities = async (
items: { sku: string }[],
orgId: string,
prisma: Prisma.DefaultPrismaClient,
): Promise<Record<string, BackOrderQueue | undefined>> => {
const skus = items.map((i) => i.sku).filter((sku) => sku !== null);
return buildIdentityMap(
await prisma.backOrderQueue.findMany({
where: { orgId, sku: { in: skus } },
}),
(i) => i.sku,
);
};
Nurul
Nurul•2mo ago
So even though there is a condition to filter out nulls in the deployed code:
const skus = items.map((i) => i.sku).filter((sku) => sku !== null);
const skus = items.map((i) => i.sku).filter((sku) => sku !== null);
Somehow Null is still being passed to the query? This is strange! Can you add a log statement just above the query to temporarily debug this? Something like this:
console.log(`Executing findMany with orgId: ${orgId} and skus:`, skus);
console.log(`Executing findMany with orgId: ${orgId} and skus:`, skus);
Giovani Granzotto
Giovani GranzottoOP•2mo ago
@Nurul Correct. We've added the log statement you mentioned and it is still erroring out even though we can see in the logs (both our custom log AND prisma's internal validation error log) that the list of arguments does not contain null values. This is the log I'm seeing on vercel:
No description
No description
Giovani Granzotto
Giovani GranzottoOP•2mo ago
log transcript:
Executing backorder findMany with orgId: org_2kkwpfy6QEpuF9w0xVYA5Ikb2xy and skus: [
'107082022484',
'107082022492',
'107082004816',
'107082020113',
'107082022495',
'107085008705',
'107082022450'
]
PrismaClientValidationError:
Invalid `prisma.backOrderQueue.findMany()` invocation:

{
where: {
orgId: "org_2kkwpfy6QEpuF9w0xVYA5Ikb2xy",
sku: {
in: [
"107082022484",
"107082022492",
"107082004816",
"107082020113",
"107082022495",
"107085008705",
"107082022450"
]
}
}
}

Argument `in`: Invalid value provided. Expected ListStringFieldRefInput, provided (Null, Null, Null, Null, Null, Null, Null).
at An (/var/task/node_modules/@prisma/client/runtime/library.js:114:7526)
at _n.handleRequestError (/var/task/node_modules/@prisma/client/runtime/library.js:121:7392)
at _n.handleAndLogRequestError (/var/task/node_modules/@prisma/client/runtime/library.js:121:7057)
at _n.request (/var/task/node_modules/@prisma/client/runtime/library.js:121:6741)
at async Array.$allOperations (/var/task/.next/server/chunks/4499.js:38:691)
at async l (/var/task/node_modules/@prisma/client/runtime/library.js:130:9355)
at async k (/var/task/.next/server/app/api/inventory/order/[orderId]/route.js:1:5696)
at async Promise.all (index 0)
at async s.Z.$transaction.maxWait (/var/task/.next/server/app/api/inventory/order/[orderId]/route.js:1:4848)
at async Proxy._transactionWithCallback (/var/task/node_modules/@prisma/client/runtime/library.js:130:7722) {
clientVersion: '5.17.0'
}
Executing backorder findMany with orgId: org_2kkwpfy6QEpuF9w0xVYA5Ikb2xy and skus: [
'107082022484',
'107082022492',
'107082004816',
'107082020113',
'107082022495',
'107085008705',
'107082022450'
]
PrismaClientValidationError:
Invalid `prisma.backOrderQueue.findMany()` invocation:

{
where: {
orgId: "org_2kkwpfy6QEpuF9w0xVYA5Ikb2xy",
sku: {
in: [
"107082022484",
"107082022492",
"107082004816",
"107082020113",
"107082022495",
"107085008705",
"107082022450"
]
}
}
}

Argument `in`: Invalid value provided. Expected ListStringFieldRefInput, provided (Null, Null, Null, Null, Null, Null, Null).
at An (/var/task/node_modules/@prisma/client/runtime/library.js:114:7526)
at _n.handleRequestError (/var/task/node_modules/@prisma/client/runtime/library.js:121:7392)
at _n.handleAndLogRequestError (/var/task/node_modules/@prisma/client/runtime/library.js:121:7057)
at _n.request (/var/task/node_modules/@prisma/client/runtime/library.js:121:6741)
at async Array.$allOperations (/var/task/.next/server/chunks/4499.js:38:691)
at async l (/var/task/node_modules/@prisma/client/runtime/library.js:130:9355)
at async k (/var/task/.next/server/app/api/inventory/order/[orderId]/route.js:1:5696)
at async Promise.all (index 0)
at async s.Z.$transaction.maxWait (/var/task/.next/server/app/api/inventory/order/[orderId]/route.js:1:4848)
at async Proxy._transactionWithCallback (/var/task/node_modules/@prisma/client/runtime/library.js:130:7722) {
clientVersion: '5.17.0'
}
Nurul
Nurul•2mo ago
This is interesting! 🤔 Do you see any patterns on when this error happens? Is it completely sporadic? Can you try upgrading to latest prisma version and check?
Giovani Granzotto
Giovani GranzottoOP•4w ago
It happens at only one point in the code, even though similar queries with the in filtering exist elsewhere. There's nothing very remarkable about it. We might upgrade the prisma client in a future update and will let you know if it continues happening.
Giovani Granzotto
Giovani GranzottoOP•7d ago
@Nurul I'm running prisma 6.2.1 and this is still happening. Any ideas?
No description
Giovani Granzotto
Giovani GranzottoOP•7d ago
Mysteriously, it keeps happening even with queryRaw
No description
Giovani Granzotto
Giovani GranzottoOP•7d ago
same with query raw unsafe
No description
Nurul
Nurul•2d ago
Nothing comes to my mind as of now. We need a way to reliably reproduce this behaviour in order to debug this 😅

Did you find this page helpful?