Promise.all in interactive $transaction unexpectedly merges operations #23845
-
Bug descriptionWe found some weird behavior when using Promise.all inside interactive transactions. How to reproduceInside an interactive $transaction, make two findUnique queries, each for a different unique field, batched together with a Promise.all (to hopefully reduce impact of network latency). Expected behaviorTwo queries should be made. The result of Promise.all should contain the result of each one. Instead, only one query is made with a merge of the where conditions of both operations. The result of Promise.all contains the result of the query and a null. Prisma informationdatasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client_js {
provider = "prisma-client-js"
output = "../node/prisma"
binaryTargets = ["debian-openssl-1.1.x", "debian-openssl-3.0.x", "linux-musl"]
}
// ...
model User {
user_id String @id @default(uuid())
email String @unique
// ...
stripe_customer_id String? @unique
} await this.db.$transaction(async (tx) => {
const [userMatch, customerMatch] = await Promise.all([
tx.user.findUnique({ where: { user_id }),
tx.user.findUnique({ where: { stripe_customer_id }}),
]);
console.log("userMatch", userMatch);
console.log("customerMatch", customerMatch);
}); Debug logsprisma:query BEGIN prisma:client Prisma Client call: +473ms prisma:client prisma.user.findUnique({ where: { user_id: "805aa449-3120-458b-9bf9-0c3beef0d47e" } }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "User", "action": "findUnique", "query": { "arguments": { "where": { "user_id": "805aa449-3120-458b-9bf9-0c3beef0d47e" } }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client Prisma Client call: +0ms prisma:client prisma.user.findUnique({ where: { stripe_customer_id: "cus_PtSOvgsLPWntH7" } }) +0ms prisma:client Generated request: +0ms prisma:client { "modelName": "User", "action": "findUnique", "query": { "arguments": { "where": { "stripe_customer_id": "cus_PtSOvgsLPWntH7" } }, "selection": { "$composites": true, "$scalars": true } } } +0ms prisma:client:libraryEngine requestBatch +1ms prisma:query SELECT "public"."user"."user_id", "public"."user"."enabled", "public"."user"."email", "public"."user"."email_confirmed", "public"."user"."roles", "public"."user"."created_at", "public"."user"."last_login", "public"."user"."stripe_customer_id" FROM "public"."user" WHERE ("public"."user"."user_id" = $1 OR "public"."user"."stripe_customer_id" = $2) OFFSET $3 userMatch { user_id: '805aa449-3120-458b-9bf9-0c3beef0d47e', enabled: true, email: 'arthur.melin@wiseone.io', email_confirmed: false, roles: [], created_at: 2024-04-09T15:03:25.406Z, last_login: 2024-04-09T15:03:25.889Z, stripe_customer_id: 'cus_PtSOvgsLPWntH7' } customerMatch null prisma:query COMMIT Environment & setup
Prisma Version
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @ArthurMelin 👋 Thank you for raising this. I can reproduce this and would consider this a bug on our end. I'll transfer this discussion to an issue. |
Beta Was this translation helpful? Give feedback.
Hi @ArthurMelin 👋
Thank you for raising this. I can reproduce this and would consider this a bug on our end. I'll transfer this discussion to an issue.