-
Notifications
You must be signed in to change notification settings - Fork 2.1k
called Option::unwrap() on a None value when using the relationJoins preview feature with driver adapters #22294
Copy link
Copy link
Closed
Labels
bug/2-confirmedBug has been reproduced and confirmed.Bug has been reproduced and confirmed.kind/bugA reported bug.A reported bug.topic: driverAdapterstopic: previewFeaturesIssue touches on an preview feature flagIssue touches on an preview feature flagtopic: relationJoins
Milestone
Description
Bug description
I updated to 5.7.0 today and tried the preview features relationJoins and nativeDistinct. I'm also using driverAdapters with Neon DB.
I am attempting to do a prisma findFirst with some nested includes:
const user = await db.user.findFirst({
where: {
id: 1,
},
include: {
accountExecutives: {
include: {
vendor: true,
},
},
},
});If I point the DB to my local, non-Neon DB everything works fine.
{
"user": {
"id": 1,
...
"accountExecutives": [
{
"id": 1,
...
"vendor": {
"id": 1,
...
}
}
]
}
}However when I point it to my Neon DB I get the following error:
Error while processing the request
PrismaClientRustPanicError:
Invalid `prisma.user.findFirst()` invocation:
called `Option::unwrap()` on a `None` value
This is a non-recoverable error which probably happens when the Prisma Query Engine has a panic.
{"name":"PrismaClientRustPanicError","clientVersion":"5.7.0"}How to reproduce
// schema.prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters", "relationJoins", "nativeDistinct"]
}
model AccountExecutive {
id Int @id @default(autoincrement())
vendor Vendor @relation(fields: [vendorId], references: [id], onDelete: Cascade)
vendorId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int
@@unique([userId, vendorId])
@@index([userId])
@@index([vendorId])
}
model User {
id Int @id @default(autoincrement())
accountExecutives AccountExecutive[]
}
model Vendor {
id Int @id @default(autoincrement())
accountExecutives AccountExecutive[]
}// db.js
import { Pool, neonConfig } from '@neondatabase/serverless';
import { PrismaNeon } from '@prisma/adapter-neon';
import { PrismaClient } from '@prisma/client';
import ws from 'ws';
import { IS_DEV } from '~/app/core/config';
neonConfig.webSocketConstructor = ws;
const connectionString = `${process.env.DATABASE_URL}`;
const pool = new Pool({ connectionString });
const adapter = new PrismaNeon(pool);
const prismaClientSingleton = () => {
return new PrismaClient({
...(!process.env.DATABASE_URL?.includes('127.0.0.1') && { adapter }),
log: IS_DEV
? ['query', 'info', 'warn', 'error']
: ['info', 'warn', 'error'],
});
};
type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClientSingleton | undefined;
};
const prisma = globalForPrisma.prisma ?? prismaClientSingleton();
if (IS_DEV) globalForPrisma.prisma = prisma;
export * from '@prisma/client';
const db = prisma;
export default db;// pages/api/prisma-570.ts
import { api } from '~/app/blitz-server';
import { APP_ENV } from '~/app/core/config';
import db from '~/db';
const handler = api(async (_req, res, ctx) => {
if (APP_ENV !== 'development' && APP_ENV !== 'preview')
return res.status(404).send('Not found');
const user = await db.user.findFirst({
where: {
id: 1,
},
include: {
accountExecutives: {
include: {
vendor: true,
},
},
},
});
res.status(200).json({
user: user,
});
});
export default handler;Environment & setup
- OS: macOS
- Database: PostgreSQL (hosted on Neon, using
@prisma/adapter-neonand@neondatabase/serverless - Node.js version: 20
Prisma Version
prisma : 5.7.0
@prisma/client : 5.7.0
Computed binaryTarget : darwin-arm64
Operating System : darwin
Architecture : arm64
Node.js : v20.8.1
Query Engine (Node-API) : libquery-engine 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9 (at node_modules/.pnpm/@prisma+engines@5.7.0/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine : schema-engine-cli 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9 (at node_modules/.pnpm/@prisma+engines@5.7.0/node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm : @prisma/prisma-schema-wasm 5.7.0-41.79fb5193cf0a8fdbef536e4b4a159cad677ab1b9
Default Engines Hash : 79fb5193cf0a8fdbef536e4b4a159cad677ab1b9
Studio : 0.495.0
Preview Features : driverAdapters, nativeDistinct, relationJoins
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bug/2-confirmedBug has been reproduced and confirmed.Bug has been reproduced and confirmed.kind/bugA reported bug.A reported bug.topic: driverAdapterstopic: previewFeaturesIssue touches on an preview feature flagIssue touches on an preview feature flagtopic: relationJoins