Skip to content

Option::unwrap() on a None value for specific operations when enabling relationJoins feature #25802

@gapuchi

Description

@gapuchi

Bug description

Hi team,

I'm testing out the relationJoins feature, but I'm getting an error when trying to run certain queries.

The errors I'm seeing:

thread 'tokio-runtime-worker' panicked at query-engine/core/src/query_document/mod.rs:83:86:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
PANIC: called `Option::unwrap()` on a `None` value

It is not failing for all calls, but the one provided below. I have a suspicion that it is due to the unique constraint on two keys. Note that I'm using query still, so I was expecting the behavior to be unchanged

How to reproduce

  • Enable relationJoins
  • Extend client to insert query
const OPERATIONS_WITH_RELATION_JOIN = [
  'findUnique',
  'findUniqueOrThrow',
  'findFirst',
  'findFirstOrThrow',
  'findMany',
  'create',
  'delete',
  'update',
  'upsert',
]

...

client.$extends({
      query: {
        $allModels: {
          async $allOperations({ query, args, operation }) {
            return OPERATIONS_WITH_RELATION_JOIN.includes(operation)
              ? query({ relationLoadStrategy: 'query', ...args })
              : query(args)
          },
        },
      },
    })

Expected behavior

No response

Prisma information

model WorkerShift {
  id                           String                        @id @default(uuid())
  worker                       Worker                        @relation(fields: [workerId], references: [id])
  workerId                     String
  shift                        Shift                         @relation(fields: [shiftId], references: [id])
  shiftId                      String
  ...

  @@unique([workerId, shiftId])
  ...
}
await Promise.all([
  this.prisma.client.workerShift.findUniqueOrThrow({
        where: { workerId_shiftId: { workerId, shiftId } } 
  }),
  ...
])

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: v20.17.0

Prisma Version

❯ npx prisma -v
prisma                  : 5.21.1
@prisma/client          : 5.21.1
Computed binaryTarget   : darwin-arm64
Operating System        : darwin
Architecture            : arm64
Node.js                 : v20.17.0
Query Engine (Node-API) : libquery-engine bf0e5e8a04cada8225617067eaa03d041e2bba36 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine           : schema-engine-cli bf0e5e8a04cada8225617067eaa03d041e2bba36 (at node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm             : @prisma/prisma-schema-wasm 5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36
Default Engines Hash    : bf0e5e8a04cada8225617067eaa03d041e2bba36
Studio                  : 0.503.0
Preview Features        : metrics, postgresqlExtensions, views, relationJoins

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions