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

PANIC: called Option::unwrap() on a None value in query-engine/core/src/interpreter/query_interpreters/nested_read.rs:232:50 #13340

Closed
janpio opened this issue May 12, 2022 · 2 comments · Fixed by prisma/prisma-engines#2973
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/schema Issue for team Schema. topic: mysql topic: nested read https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#nested-reads topic: rust panic topic: schema validation
Milestone

Comments

@janpio
Copy link
Member

janpio commented May 12, 2022

This issue is based on the information and reproduction provided in #8691

A simplified reproduction can be found at: https://github.com/janpio/prisma-relation-panic

The failing Prisma Client and Query Engine is probably only a symptom though - the schema is actually invalid as it is missing @unique on A.custom_id but is accepted by the tooling for some weird reason. For SQLite and PostgreSQL providers the schema is actually invalid with:

Error validating: The argument `references` must refer to a unique criteria in the related model `A`. But it is referencing the following fields that are not a unique criteria: custom_id`

Versions

Name Version
Node v16.14.2
OS debian-openssl-1.1.x
Prisma Client 3.14.0
Database mysql

Logs

gitpod /workspace/prisma-relation-panic (main) $ npm run start

> prisma-relation-panic@1.0.0 start
> ts-node index.ts

  prisma:tryLoadEnv Environment variables not found at null +0ms
  prisma:tryLoadEnv Environment variables loaded from /workspace/prisma-relation-panic/prisma/.env +2ms
  prisma:tryLoadEnv Environment variables not found at null +2ms
  prisma:tryLoadEnv Environment variables loaded from /workspace/prisma-relation-panic/prisma/.env +0ms
  prisma:client dirname /workspace/prisma-relation-panic/node_modules/.prisma/client +0ms
  prisma:client relativePath ../../../prisma +0ms
  prisma:client cwd /workspace/prisma-relation-panic/prisma +0ms
  prisma:client clientVersion: 3.14.0 +2ms
  prisma:client clientEngineType: library +0ms
  prisma:client:libraryEngine internalSetup +0ms
  prisma:client Prisma Client call: +45ms
  prisma:client prisma.a.findMany({
  prisma:client   select: {
  prisma:client     B: {
  prisma:client       select: {
  prisma:client         A: {
  prisma:client           select: {
  prisma:client             id: true,
  prisma:client             custom_id: true
  prisma:client           }
  prisma:client         }
  prisma:client       }
  prisma:client     }
  prisma:client   }
  prisma:client }) +1ms
  prisma:client Generated request: +1ms
  prisma:client query {
  prisma:client   findManyA {
  prisma:client     B {
  prisma:client       A {
  prisma:client         id
  prisma:client         custom_id
  prisma:client       }
  prisma:client     }
  prisma:client   }
  prisma:client }
  prisma:client  +0ms
  prisma:client:libraryEngine sending request, this.libraryStarted: false +46ms
  prisma:client:libraryEngine Searching for Query Engine Library in /workspace/prisma-relation-panic/node_modules/.prisma/client +45ms
  prisma:client:libraryEngine loadEngine using /workspace/prisma-relation-panic/node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node +0ms
  prisma:client:libraryEngine library starting +5ms
prisma:info Starting a mysql pool with 17 connections.
  prisma:client:libraryEngine library started +124ms
prisma:query SELECT `scarlet_whale`.`A`.`id`, `scarlet_whale`.`A`.`custom_id` FROM `scarlet_whale`.`A` WHERE 1=1
prisma:query SELECT `scarlet_whale`.`B`.`id`, `scarlet_whale`.`B`.`a_id` FROM `scarlet_whale`.`B` WHERE `scarlet_whale`.`B`.`a_id` IN (?)
thread 'tokio-runtime-worker' panicked at 'called `Option::unwrap()` on a `None` value', query-engine/core/src/interpreter/query_interpreters/nested_read.rs:232:50
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
prisma:query SELECT `scarlet_whale`.`A`.`id`, `scarlet_whale`.`A`.`custom_id` FROM `scarlet_whale`.`A` WHERE `scarlet_whale`.`A`.`custom_id` IN (?)
prisma:error PANIC: called `Option::unwrap()` on a `None` value in query-engine/core/src/interpreter/query_interpreters/nested_read.rs:232:50

[...]

  prisma:client:request_handler Error: called `Option::unwrap()` on a `None` value
  prisma:client:request_handler     at prismaGraphQLToJSError (/workspace/prisma-relation-panic/node_modules/@prisma/client/runtime/index.js:39469:10)
  prisma:client:request_handler     at Object.request (/workspace/prisma-relation-panic/node_modules/@prisma/client/runtime/index.js:41333:17)
  prisma:client:request_handler     at async Object.request (/workspace/prisma-relation-panic/node_modules/@prisma/client/runtime/index.js:45375:24)
  prisma:client:request_handler     at async PrismaClient._request (/workspace/prisma-relation-panic/node_modules/@prisma/client/runtime/index.js:46301:18)
  prisma:client:request_handler     at async main (/workspace/prisma-relation-panic/index.ts:8:18) +0ms
  prisma:client:libraryEngine hookProcess received: exit +86ms
  prisma:client:libraryEngine runBeforeExit +0ms
/workspace/prisma-relation-panic/node_modules/@prisma/client/runtime/index.js:45409
        throw new PrismaClientUnknownRequestError(message, this.client._clientVersion);
              ^
PrismaClientUnknownRequestError: 
Invalid `prisma.a.findMany()` invocation in
/workspace/prisma-relation-panic/index.ts:8:33

   5 })
   6 
   7 async function main() {
→  8   const result = await prisma.a.findMany(
  called `Option::unwrap()` on a `None` value
    at Object.request (/workspace/prisma-relation-panic/node_modules/@prisma/client/runtime/index.js:45409:15)
    at async PrismaClient._request (/workspace/prisma-relation-panic/node_modules/@prisma/client/runtime/index.js:46301:18)
    at async main (/workspace/prisma-relation-panic/index.ts:8:18) {
  clientVersion: '3.14.0'
}

Client Snippet

  const result = await prisma.a.findMany({
    select: {
      B: {
        select: {
          A: {
            select: {
              id: true,
              custom_id: true
            },
          },
        },
      },
    },
  })

Schema

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

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

model A {
  id         Int          @id @default(autoincrement())
  custom_id  String
  B          B[]
  @@index([custom_id])
}

model B {
  id        Int     @id @default(autoincrement())
  a_id String
  A         A @relation(fields: [a_id], references: [custom_id])
}

Prisma Engine Query

  prisma:client query {
  prisma:client   findManyA {
  prisma:client     B {
  prisma:client       A {
  prisma:client         id
  prisma:client         custom_id
  prisma:client       }
  prisma:client     }
  prisma:client   }
  prisma:client }
@Weakky
Copy link
Member

Weakky commented Jun 22, 2022

Hey,

This was fixed by prisma/prisma-engines#2973. It'll be available in Prisma 4.x.

Thanks for reporting 🙏

@janpio janpio added this to the 4.0.0 milestone Jun 22, 2022
@Jolg42 Jolg42 added topic: rust panic topic: nested read https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#nested-reads labels Jan 17, 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. kind/bug A reported bug. team/schema Issue for team Schema. topic: mysql topic: nested read https://www.prisma.io/docs/concepts/components/prisma-client/relation-queries#nested-reads topic: rust panic topic: schema validation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants