prisma: Prisma crashes with `This is a non-recoverable error which probably happens when the Prisma Query Engine has a panic.`
Bug description
Prisma panics on a valid query.
I make this Prisma call:
await prisma.book_share_email_invitations.findOne({
select: {
id: true,
book_id: true,
book: {
select: {
id: true,
name: true,
shelf: { select: { id: true, name: true } },
},
},
email: true,
permission: true,
// vvv This is the problematic part
last_sent_user: {
select: {
id: true,
name: true,
first_name: true,
last_name: true,
},
},
},
where: { auth_token },
})
In the query, I request last_sent_user
which is a relation based on the field last_sent_by
(full schema shown later).
Additional details:
- This isn’t the default name for the relation which would be
users
; however,last_sent_user
is more representative of what the relation is. - The
last_sent_user
related record does exist. I checked it manually and the relatedusers.id
exists in the database. - If I remove
last_sent_user
from the query, it executes without error. - The book relation works fine.
The error is:
Error at path "api/pages/share/book/[auth_token].ts" on method "entry":
Invalid `prisma.book_share_email_invitations.findOne()` invocation in
/Users/sunnyhirai/Projects/airshelf/api/pages/share/book/[auth_token].ts:8:52
4 async function getInvitation(
5 [object Object], auth_token ,[object Object],[object Object], ,[object Object], auth_token,[object Object], string ,[object Object],[object Object],
6 ,[object Object], prisma ,[object Object],[object Object], ,[object Object],[object Object],Context
7 ) {
→ 8 return await prisma.book_share_email_invitations.findOne(
PANIC: Application logic invariant error: received null value for field last_sent_user which may not be null
This is a non-recoverable error which probably happens when the Prisma Query Engine has a panic.
As can be seen in the error, Prisma is expected to receive a value for last_sent_user
:
SELECT "public"."book_share_email_invitations"."id", "public"."book_share_email_invitations"."book_id", "public"."book_share_email_invitations"."email", "public"."book_share_email_invitations"."permission", "public"."book_share_email_invitations"."book_id", "public"."book_share_email_invitations"."last_sent_by" FROM "public"."book_share_email_invitations" WHERE "public"."book_share_email_invitations"."auth_token" = $1 LIMIT $2 OFFSET $3
How to reproduce
I’ve provided details below but a minimal reproduction may be hard to create because my other relations work fine. I don’t know what is special about this one that makes it crash other than the naming is a little different (however, other relations are renamed to use a singular form in many cases).
Expected behavior
Should not panic.
Prisma information
These are the immediate models related to this query.
model book_share_email_invitations {
auth_token String @unique
book_id Int
email String
id Int @default(autoincrement()) @id
last_sent_by Int
permission Int
// normalized (singularized)
book books @relation(fields: [book_id], references: [id])
// normalized (singularized)
last_sent_user users @relation(fields: [last_sent_by], references: [id])
@@index([book_id], name: "book_share_email_invitations_book_id_index")
@@unique([book_id, email], name: "book_share_email_invitations_book_id_email_unique")
}
model users {
created_at Int
email String @unique
first_name String
id Int @id
last_name String
name String @unique
password_hash String?
// normalized (singularized)
shelf shelves @relation(fields: [id], references: [id])
// normalized (no change)
book_marks book_marks[]
// normalized (no change)
book_share_email_invitations book_share_email_invitations[]
// normalized (no change)
book_shares book_shares[]
// normalized (no change)
notifications notifications[]
// normalized (no change)
page_edit_sessions page_edit_sessions[]
// normalized (no change)
page_marks page_marks[]
// normalized (no change)
pages pages[]
// normalized (no change)
sessions sessions[]
// normalized (no change)
user_starred_books user_starred_books[]
}
model books {
counter Int @default(0)
created_at Int
id Int @default(autoincrement()) @id
name String
privacy Int
shelf_id Int
title String
toc Json
updated_at Int
// normalized (singularized)
shelf shelves @relation(fields: [shelf_id], references: [id])
// normalized (no change)
book_marks book_marks[]
// normalized (no change)
book_share_email_invitations book_share_email_invitations[]
// normalized (no change)
book_shares book_shares[]
// normalized (no change)
pages pages[]
// normalized (no change)
shelf_pinned_books shelf_pinned_books[]
// normalized (no change)
user_starred_books user_starred_books[]
@@unique([shelf_id, name], name: "books_shelf_id_name_unique")
}
Environment & setup
- OS: Mac OS
- Database: PostgreSQL
- Prisma version: 2.0.0
- Node.js version: v12.16.2
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 24 (11 by maintainers)
I just encountered this error, I wanted to query a table with ‘currentStatus’ using groupBy, but in my db it was saved as null instead of a string, so as soon as I changed the value in my db, the error was gone and query was made.
Oh, my apologies. I used the dump feature in Heroku which I don’t have much experience with.
I will try again.
@thesunny You can email it to “schemas@prisma.io”. If you want us to sign an NDA, we can also do that.
@janpio How should I send the file to you? I have it ready.