Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal query batching fails when the table name is 'stores' #20324

Closed
roshan1988 opened this issue Jul 21, 2023 · 4 comments
Closed

Internal query batching fails when the table name is 'stores' #20324

roshan1988 opened this issue Jul 21, 2023 · 4 comments
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: batching topic: broken query
Milestone

Comments

@roshan1988
Copy link

roshan1988 commented Jul 21, 2023

Bug description

I have one of my table named 'stores' in postgres.

When there is a findUnique for stores, the query works fine, and returns the value correctly.

But when there are multiple findUniques for the 'stores' table, and when prisma is internally batching them, client is returning null value for all of the calls.

This happens only when I move to the jsonProtocol supported versions of prisma.

The internal queries seems to be created correctly by prisma though.

SELECT "public"."stores"."id", "public"."stores"."displayName" FROM "public"."stores" WHERE (("public"."stores"."id" = $1 AND "public"."stores"."status" = $2) OR ("public"."stores"."id" = $3 AND "public"."stores"."status" = $4)) OFFSET $5

So I am guessing something is going wrong while mapping them back to the prisma models and returning null

How to reproduce

Expected behavior

No response

Prisma information

model Stores {
  id                     String                   @id @default(cuid())
  displayName            String
  status StoreStatus
  @@map("stores")
}
// Add your code using Prisma Client

Environment & setup

  • OS: All envioronments
  • Database: PostgreSQL
  • Node.js version: 18.5

Prisma Version

5.0.0
@roshan1988 roshan1988 added the kind/bug A reported bug. label Jul 21, 2023
@millsp
Copy link
Member

millsp commented Jul 21, 2023

Thanks for the report @roshan1988. Could you please also share the findUnique query that you are using? I was not able to simply reproduce in a simple project, so the reproduction may be more involved (I also tried with a different schema). Could you please provide us with a small repro (with a part of your schema, and the code triggering this)?

const data = await Promise.all([
    prisma.user.findUnique({ where: { id: 1 } }),
    prisma.user.findUnique({ where: { id: 2 } }),
    prisma.user.findUnique({ where: { id: 3 } }),
    prisma.user.findUnique({ where: { id: 4 } }),
    prisma.user.findUnique({ where: { id: 5 } }),
    prisma.user.findUnique({ where: { id: 6 } }),
    prisma.user.findUnique({ where: { id: 7 } }),
    prisma.user.findUnique({ where: { id: 8 } }),
    prisma.user.findUnique({ where: { id: 9 } }),
])

@millsp millsp added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. tech/engines Issue for tech Engines. topic: broken query team/client Issue for team Client. topic: batching labels Jul 21, 2023
@SevInf
Copy link
Contributor

SevInf commented Jul 24, 2023

Hi @roshan1988.
It looks to me like the name of the model has nothing to do with it, and this is issue is rather a duplicate of #20227. Could you check if still happens on 5.1.0-dev.15 snapshot version, mentioned in the issue? We don't recommend using dev versions in production, but this will help to ensure that you problem is fixed in Prisma 5.1

@roshan1988
Copy link
Author

Hi @roshan1988. It looks to me like the name of the model has nothing to do with it, and this is issue is rather a duplicate of #20227. Could you check if still happens on 5.1.0-dev.15 snapshot version, mentioned in the issue? We don't recommend using dev versions in production, but this will help to ensure that you problem is fixed in Prisma 5.1

Thanks @SevInf for the reply. I am able to make this work with 5.1.0-dev.15. Will wait for the official 5.1 release

@SevInf
Copy link
Contributor

SevInf commented Jul 25, 2023

Thanks for getting back to us and confirming it is fixed!
5.1 will be released in a week and since the problem is solved, I am going to close this issue now.

@SevInf SevInf closed this as completed Jul 25, 2023
@Jolg42 Jolg42 added this to the 5.1.0 milestone Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: batching topic: broken query
Projects
None yet
Development

No branches or pull requests

4 participants