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

Error query by UUID in batched queries #13552

Open
GenrikhFetischev opened this issue May 29, 2022 · 2 comments · May be fixed by prisma/prisma-engines#4857
Open

Error query by UUID in batched queries #13552

GenrikhFetischev opened this issue May 29, 2022 · 2 comments · May be fixed by prisma/prisma-engines#4857
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug. tech/engines Issue for tech Engines. topic: batching topic: uuid

Comments

@GenrikhFetischev
Copy link

GenrikhFetischev commented May 29, 2022

Bug description

Prisma can't understand that two different strings could be the same UUID in particular cases.

Strings "11111111111111111111111111111111" and "11111111-1111-1111-1111-111111111111" are the same UUID and are treated equally by Postgres.

A bug appears when Prisma trying to batch a few findUnique({where: {id}}); queries, where id is UUID srting without dashes, like there SELECT "public"."Cup"."id" FROM "public"."Cup" WHERE "public"."Cup"."id" IN ($1,$2)
Even if records with ids passed to the request above exist in DB Prisma will return null, while following request SELECT "public"."Cup"."id" FROM "public"."Cup" WHERE "public"."Cup"."id" = $1 OFFSET $2 with the same ids as in the previous one will return records.

I've created a little repository where is possible to reproduce the bug, some logs from that:

Upserting record into DB
prisma:query BEGIN
Query BEGIN
Params []
prisma:query SELECT "public"."Cup"."id" FROM "public"."Cup" WHERE "public"."Cup"."id" = $1 OFFSET $2
Query SELECT "public"."Cup"."id" FROM "public"."Cup" WHERE "public"."Cup"."id" = $1 OFFSET $2
Params ["11111111111111111111111111111111",0]
prisma:query SELECT "public"."Cup"."id" FROM "public"."Cup" WHERE "public"."Cup"."id" = $1
Query SELECT "public"."Cup"."id" FROM "public"."Cup" WHERE "public"."Cup"."id" = $1
Params ["11111111111111111111111111111111"]
prisma:query SELECT "public"."Cup"."id" FROM "public"."Cup" WHERE "public"."Cup"."id" = $1 LIMIT $2 OFFSET $3
Query SELECT "public"."Cup"."id" FROM "public"."Cup" WHERE "public"."Cup"."id" = $1 LIMIT $2 OFFSET $3
Params ["11111111-1111-1111-1111-111111111111",1,0]
prisma:query COMMIT
Query COMMIT
Params []
____________________ 


prisma:query SELECT "public"."Cup"."id" FROM "public"."Cup" WHERE "public"."Cup"."id" = $1 LIMIT $2 OFFSET $3
Query SELECT "public"."Cup"."id" FROM "public"."Cup" WHERE "public"."Cup"."id" = $1 LIMIT $2 OFFSET $3
Params ["11111111111111111111111111111111",1,0]
There we can see that value is presented in  DB
{ id: '11111111-1111-1111-1111-111111111111' }
____________________ 


prisma:query SELECT "public"."Cup"."id" FROM "public"."Cup" WHERE "public"."Cup"."id" IN ($1,$2) OFFSET $3
Query SELECT "public"."Cup"."id" FROM "public"."Cup" WHERE "public"."Cup"."id" IN ($1,$2) OFFSET $3
Params ["11111111111111111111111111111111","11111111111111111111111111111111",0]
But there is nulls
[ null, null ]
____________________ 


prisma:query SELECT "public"."Cup"."id" FROM "public"."Cup" WHERE "public"."Cup"."id" IN ($1,$2) OFFSET $3
Query SELECT "public"."Cup"."id" FROM "public"."Cup" WHERE "public"."Cup"."id" IN ($1,$2) OFFSET $3
Params ["11111111-1111-1111-1111-111111111111","11111111-1111-1111-1111-111111111111",0]
But there is works
[
  { id: '11111111-1111-1111-1111-111111111111' },
  { id: '11111111-1111-1111-1111-111111111111' }
]

How to reproduce

  1. Clone https://github.com/GenrikhFetischev/prisma-problem
  2. Set DATABASE_URL env
  3. Run pnpm install
  4. Run pnpm try
  5. Check stdout

Expected behavior

Batched queries should return records that exist in DB.

Prisma information

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}


model Cup {
    id  String   @id @default(uuid()) @map("id") @db.Uuid
}

Environment & setup

  • OS: Mac Os
  • Database: PostgreSQL
  • Node.js version: 17.9

Prisma Version

prisma                  : 3.14.0
@prisma/client          : 3.14.0
Current platform        : darwin
Query Engine (Node-API) : libquery-engine 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/.pnpm/@prisma+engines@3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/.pnpm/@prisma+engines@3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a/node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/.pnpm/@prisma+engines@3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a/node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/.pnpm/@prisma+engines@3.14.0-36.2b0c12756921c891fec4f68d9444e18c7d5d4a6a/node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash    : 2b0c12756921c891fec4f68d9444e18c7d5d4a6a
Studio                  : 0.460.0

@GenrikhFetischev GenrikhFetischev added the kind/bug A reported bug. label May 29, 2022
@jkomyno jkomyno added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. labels May 30, 2022
@janpio janpio added domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. topic: uuid and removed domain/schema Issue in the "Schema" domain: Prisma Schema, Introspection, Migrations etc. labels May 31, 2022
@garrensmith garrensmith added tech/engines Issue for tech Engines. size/s labels Jul 1, 2022
@xhjkl
Copy link

xhjkl commented Jul 18, 2022

@garrensmith, thank you for labelling this issue! I understand how busy you were releasing 4.0.0, and I'm very grateful for Prisma to you and the whole team. Alas, I still could reproduce this issue with prisma@4.0.0; maybe you could invest a minute to this bug also, or at least point me to the right direction on how could I fix it myself?

@pimeys pimeys self-assigned this Sep 2, 2022
@pimeys
Copy link
Contributor

pimeys commented Sep 2, 2022

I can reproduce this. It's now part of our correctness initiative and I'm pushing this to be fixed.

For the developer fixing this: the batching fails, and there's logic to combine similar queries to a single findMany in the core. I'd take a look if we do something stupid there with uuid parsing.

@pimeys pimeys added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Sep 2, 2022
@pimeys pimeys removed their assignment Sep 2, 2022
@SevInf SevInf self-assigned this Nov 9, 2022
@Druue Druue self-assigned this May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. domain/client Issue in the "Client" domain: Prisma Client, Prisma Studio etc. kind/bug A reported bug. tech/engines Issue for tech Engines. topic: batching topic: uuid
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants