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

Attempting to do a query in the Prisma Client on a model with a foreign key that has @map panics on 3.10.0 #12105

Closed
emmatown opened this issue Mar 2, 2022 · 2 comments
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: relations
Milestone

Comments

@emmatown
Copy link

emmatown commented Mar 2, 2022

Bug description

Attempting to do a query in the Prisma Client on a model with a foreign key that has @map panics on 3.10.0. An example schema and script to do a query is below. This didn't occur in 3.9 or below.

How to reproduce

  1. Have the Prisma schema shown below
  2. Run the Node script below to try to create an item that has a foreign key with @map with RUST_BACKTRACE=1 DEBUG="*" node index.js
  3. Get the following error:
    prisma:tryLoadEnv Environment variables not found at null +0ms
    prisma:tryLoadEnv Environment variables not found at undefined +1ms
    prisma:tryLoadEnv No Environment variables loaded +0ms
    prisma:tryLoadEnv Environment variables not found at null +0ms
    prisma:tryLoadEnv Environment variables not found at undefined +0ms
    prisma:tryLoadEnv No Environment variables loaded +0ms
    prisma:client clientVersion: 3.10.0 +0ms
    prisma:client clientEngineType: library +0ms
    prisma:client:libraryEngine internalSetup +0ms
    prisma:client Prisma Client call: +4ms
    prisma:client prisma.post.create({
    prisma:client   data: {}
    prisma:client }) +1ms
    prisma:client Generated request: +0ms
    prisma:client mutation {
    prisma:client   createOnePost(data: {
    prisma:client 
    prisma:client   }) {
    prisma:client     id
    prisma:client     authorId
    prisma:client   }
    prisma:client }
    prisma:client  +0ms
    prisma:client:libraryEngine sending request, this.libraryStarted: false +5ms
    prisma:client:libraryEngine Searching for Query Engine Library in /prisma-test/node_modules/.prisma/client +1ms
    prisma:client:libraryEngine loadEngine using /prisma-test/node_modules/.prisma/client/libquery_engine-darwin-arm64.dylib.node +0ms
    prisma:client:libraryEngine library starting +33ms
    prisma:client:libraryEngine library started +22ms
    thread 'tokio-runtime-worker' panicked at 'called `Option::unwrap()` on a `None` value', query-engine/core/src/response_ir/internal.rs:364:77
    stack backtrace:
    0: _rust_begin_unwind
    1: core::panicking::panic_fmt
    2: core::panicking::panic
    3: query_core::response_ir::internal::serialize_objects
    4: query_core::response_ir::internal::serialize_record_selection
    5: query_core::response_ir::internal::serialize_internal
    6: query_core::response_ir::ir_serializer::IrSerializer::serialize
    7: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    8: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    9: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    10: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    11: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    12: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    13: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    14: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    15: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
    16: tokio::runtime::task::harness::Harness<T,S>::poll
    17: std::thread::local::LocalKey<T>::with
    18: tokio::runtime::thread_pool::worker::Context::run_task
    19: tokio::runtime::thread_pool::worker::Context::run
    20: tokio::macros::scoped_tls::ScopedKey<T>::set
    21: tokio::runtime::thread_pool::worker::run
    22: tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut
    23: tokio::runtime::task::harness::Harness<T,S>::poll
    24: tokio::runtime::blocking::pool::Inner::run
    note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
    prisma:client:request_handler Error: called `Option::unwrap()` on a `None` value
    prisma:client:request_handler     at prismaGraphQLToJSError (/prisma-test/node_modules/@prisma/client/runtime/index.js:33915:10)
    prisma:client:request_handler     at Object.request (/prisma-test/node_modules/@prisma/client/runtime/index.js:35739:17)
    prisma:client:request_handler     at async Object.request (/prisma-test/node_modules/@prisma/client/runtime/index.js:39779:24)
    prisma:client:request_handler     at async PrismaClient._request (/prisma-test/node_modules/@prisma/client/runtime/index.js:40637:18) +0ms
    prisma:client:libraryEngine hookProcess received: exit +57ms
    prisma:client:libraryEngine runBeforeExit +0ms
    /prisma-test/node_modules/@prisma/client/runtime/index.js:39813
            throw new PrismaClientUnknownRequestError(message, this.client._clientVersion);
                ^
    
    PrismaClientUnknownRequestError: 
    Invalid `prismaClient.post.create()` invocation in
    /prisma-test/index.js:5:19
    
    2 
    3 const prismaClient = new PrismaClient();
    4 
    → 5 prismaClient.post.create(
    called `Option::unwrap()` on a `None` value
        at Object.request (/prisma-test/node_modules/@prisma/client/runtime/index.js:39813:15)
        at async PrismaClient._request (/prisma-test/node_modules/@prisma/client/runtime/index.js:40637:18) {
    clientVersion: '3.10.0'
    }
    

Expected behavior

The Query Engine doesn't panic with foreign keys that have @map

Prisma information

datasource db {
  url      = "file:./app.db"
  provider = "sqlite"
}

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

model User {
  id    String @id @default(cuid())
  posts Post[]
}

model Post {
  id       String  @id @default(cuid())
  author   User?   @relation(fields: [authorId], references: [id])
  authorId String? @map("author")
}
const { PrismaClient } = require("@prisma/client");

const prismaClient = new PrismaClient();

prismaClient.post.create({ data: {} }).then((post) => {
  console.log(post);
});

Environment & setup

  • OS: macOS
  • Database: SQLite
  • Node.js version: v16.13.0

Prisma Version

prisma                  : 3.10.0
@prisma/client          : 3.10.0
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Default Engines Hash    : 73e60b76d394f8d37d8ebd1f8918c79029f0db86
Studio                  : 0.458.0
@emmatown emmatown added the kind/bug A reported bug. label Mar 2, 2022
@janpio janpio added team/client Issue for team Client. topic: relations bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Mar 2, 2022
@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Mar 2, 2022
@pantharshit00
Copy link
Contributor

Thanks for the great reproduction. I can confirm this regression.

@pantharshit00 pantharshit00 added kind/regression A reported bug in functionality that used to work before. and removed kind/bug A reported bug. labels Mar 2, 2022
@janpio janpio added the tech/engines Issue for tech Engines. label Mar 2, 2022
@garrensmith garrensmith added this to the 3.11.0 milestone Mar 2, 2022
@garrensmith
Copy link
Contributor

To close the loop on this. We have a fix for this here prisma/prisma-engines#2732 This will be out in the 3.11 release.

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/regression A reported bug in functionality that used to work before. team/client Issue for team Client. tech/engines Issue for tech Engines. topic: relations
Projects
None yet
Development

No branches or pull requests

5 participants