thread 'tokio-runtime-worker' panicked at 'internal error: entered unreachable code: Relation fields should never hit the BSON conversion logic.', query-engine/connectors/mongodb-query-connector/src/value.rs:34:35
See original GitHub issueBug description
Nested write query fails for a 1-n relation – migration from mongoose
How to reproduce
- Clone repo
- Install dependencies
- Create
docker-compose.yml
: - Run
docker-compose up -d
- Seed database
git clone git@github.com:prisma/migrate-from-mongoose-to-prisma.git
cd migrate-from-mongoose-to-prisma
npm install
touch docker-compose.yml
touch .env
docker-compose.yml
file
version: '3'
services:
mongodb:
image: 'prismagraphql/mongo-single-replica:4.4.3-bionic'
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: prisma
ports:
- 27017:27017
Set env variable:
DATABASE_URL="mongodb://root:prisma@localhost:27017/prisma-mongo?authSource=admin&retryWrites=true&w=majority"
Start up db:
docker-compose up -d
Seed database
npm run seed
Install Prisma and Prisma Client:
npm i -D prisma && npm i @prisma/client
Initialize Prisma
npx prisma init --datasource-provider mongodb
Introspect db:
npx prisma db pull
Original schema:
type UsersProfile {
bio String
}
model categories {
id String @id @default(auto()) @map("_id") @db.ObjectId
v Int @map("__v")
name String
}
model posts {
id String @id @default(auto()) @map("_id") @db.ObjectId
v Int @map("__v")
author String @db.ObjectId
categories String[] @db.ObjectId
content String
published Boolean
title String
}
model users {
id String @id @default(auto()) @map("_id") @db.ObjectId
v Int @map("__v")
email String @unique(map: "email_1")
name String
profile UsersProfile?
}
Update relations:
// schema.prisma
type UsersProfile {
bio String
}
model Category {
id String @id @default(auto()) @map("_id") @db.ObjectId
v Int @default(0) @map("__v") @ignore
name String
posts Post[] @relation(fields: [postIds], references: [id])
postIds String[] @db.ObjectId
@@map("categories")
}
model Post {
id String @id @default(auto()) @map("_id") @db.ObjectId
title String
content String
published Boolean @default(false)
v Int @default(0) @map("__v") @ignore
author User @relation(fields: [authorId], references: [id])
authorId String @map("author") @db.ObjectId
categories Category[] @relation(fields: [categoryIds], references: [id])
categoryIds String[] @map("categories") @db.ObjectId
@@map("posts")
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
v Int @default(0) @map("__v") @ignore
email String @unique(map: "email_1")
name String
profile UsersProfile?
posts Post[]
@@map("users")
}
Push schema
npx prisma db push
Update nested write in src/controller/post.js
const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
const createDraft = async (req, res) => {
const { title, content, authorEmail } = req.body
try {
const draft = await prisma.post.create({
data: {
title,
content,
author: {
connect: {
email: authorEmail
}
},
}
})
res.status(201).json(draft)
} catch (error) {
return res.status(500).json({ error })
}
}
Start server:
RUST_BACKTRACE=1 RUST_BACKTRACE=full npm run dev
Make a request to the route:
curl -X POST http://localhost:3000/post -H 'Content-Type: application/json' -d '{ "title": "Request", "content": "no funny business", "authorEmail":"nikolas@prisma.io"}'
Error message:
thread 'tokio-runtime-worker' panicked at 'internal error: entered unreachable code: Relation fields should never hit the BSON conversion logic.', query-engine/connectors/mongodb-query-connector/src/value.rs:34:35
stack backtrace:
0: 0x114c174b1 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h4f26ffad025fdbe8
1: 0x114c3e39b - core::fmt::write::h0a9937d83d3944c1
2: 0x114c10468 - std::io::Write::write_fmt::hfaf2e2e92eda8127
3: 0x114c1a0b7 - std::panicking::default_hook::{{closure}}::hc11e9b8d348e68b0
4: 0x114c19cc5 - std::panicking::default_hook::h1d26ec4d0d63be04
5: 0x113965c93 - query_engine::engine::set_panic_hook::{{closure}}::hb13d3e90f35b7192
6: 0x114c1a76e - std::panicking::rust_panic_with_hook::hef4f5e524db188b3
7: 0x114c1a46e - std::panicking::begin_panic_handler::{{closure}}::h6e8805ea2351af89
8: 0x114c17927 - std::sys_common::backtrace::__rust_end_short_backtrace::hd383ade987b76f63
9: 0x114c1a15a - _rust_begin_unwind
10: 0x114c9b1ef - core::panicking::panic_fmt::hb58956db718d5b79
11: 0x113d2b77b - mongodb_query_connector::value::<impl mongodb_query_connector::IntoBson for (&prisma_models::field::Field,prisma_value::PrismaValue)>::into_bson::h95e4570bcf56da46
12: 0x113e1c1cf - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h3e7c9ade7ac96779
13: 0x113e4cd81 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::ha13e11dd59391f10
14: 0x113aa7550 - query_core::interpreter::query_interpreters::write::execute::{{closure}}::h8f9f7fb18890375a
15: 0x113ac886b - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h5c5d66852595493c
16: 0x113adc8f5 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::heefcba071cfe3997
17: 0x113ac3d4d - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h1e61264390b37814
18: 0x113ac3d4d - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h1e61264390b37814
19: 0x113ac38cf - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h1e61264390b37814
20: 0x113ad20ee - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h886d3d857f4347e9
21: 0x1139157cb - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::ha0afe0afe3b0af76
22: 0x1138f3662 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h0acf6fa6ac03198d
23: 0x1139044b6 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h449f4b3fca9d1dc3
24: 0x11392559a - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hda5039d17292f880
25: 0x113924bea - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hd3090eaeddd40499
26: 0x1138f755f - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h17bbed97ade6ca82
27: 0x113907796 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h5567e0f1fccd8808
28: 0x11392d446 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::hf9f999adce7ae502
29: 0x1138fda4b - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h345089d0b50ec2e5
30: 0x1138c66b9 - tokio::runtime::task::harness::poll_future::h6184305dc4cac7f4
31: 0x1138bcdb9 - tokio::runtime::task::harness::Harness<T,S>::poll::h1755f38295a1e100
32: 0x1149b042f - std::thread::local::LocalKey<T>::with::hf23d5553ac5eca59
33: 0x1149ac7bb - tokio::runtime::thread_pool::worker::Context::run_task::he6f5c6856859aa9f
34: 0x1149abb5f - tokio::runtime::thread_pool::worker::Context::run::h41e7f0d9bdf2d560
35: 0x1149994ba - tokio::macros::scoped_tls::ScopedKey<T>::set::hc3ec82ab4b030874
36: 0x1149ab654 - tokio::runtime::thread_pool::worker::run::h11ecc88dccbd5de9
37: 0x114992d43 - <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll::h27cfa8f24814c06b
38: 0x1149a384b - tokio::runtime::task::harness::Harness<T,S>::poll::h45a01de20d39e895
39: 0x114992753 - tokio::runtime::blocking::pool::Inner::run::h4fb0429750936689
40: 0x11499a501 - std::sys_common::backtrace::__rust_begin_short_backtrace::h4c5fbd74560be1c7
41: 0x1149b3bed - core::ops::function::FnOnce::call_once{{vtable.shim}}::h85677d5fd49be5ac
42: 0x114c237b7 - std::sys::unix::thread::Thread::new::thread_start::hcccd55275f17da3c
43: 0x7ff81a0d64e1 - __pthread_start
Expected behavior
Create a post document and link to existing user
Prisma information
Environment & setup
- OS: Mac OS
- Database: MongoDB
- Node.js version: 16.13.1
Prisma Version
prisma : 3.12.0
@prisma/client : 3.12.0
Current platform : darwin
Query Engine (Node-API) : libquery-engine 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 22b822189f46ef0dc5c5b503368d1bee01213980 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt 22b822189f46ef0dc5c5b503
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
entered unreachable code: received unknown error (timeout)
When crawling a website, I get this when it happens upon a certain page: thread 'tokio-runtime-worker' panicked at 'internal error: entered ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fix will ship with 3.14.
I’ve also encountered this issue. The error only appears when writing to the table.
Changing one or the other works: