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

findMany fails to select an enum list & a relation scalar at the same time #2525

Closed
sdnts opened this issue May 20, 2020 · 3 comments
Closed
Assignees
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. tech/engines Issue for tech Engines.
Milestone

Comments

@sdnts
Copy link
Contributor

sdnts commented May 20, 2020

I was tempted to post this as a comment on #2442. I have a feeling this, #2442 & #2501 are all the same issue but can't prove it, so I'm creating separate ones. Please move if you think otherwise!

Again, I first discovered this while trying to reproduce a report on Studio: prisma/studio#406

Bug description

For a model with an enum list, certain combinations of select crash

How to reproduce

Use this schema:
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = "postgresql://siddhant@localhost:5432/experiments"
}

model Startup {
  id      Int       @id
  name    String
  Contact Contact[]
}

enum ScoutingFile {
  One
  Two
}

model Contact {
  id            Int            @default(autoincrement()) @id
  firstName     String?
  lastName      String?
  email         String         @unique
  startup       Startup        @relation(fields: [startupId], references: [id])
  startupId     Int
  validEmail    Boolean        @default(true)
  scoutingFiles ScoutingFile[]
}
And this script:
const { PrismaClient } = require("@prisma/client");

const prisma = new PrismaClient();

const main = async () => {
  const contacts = await prisma.contact.create({
    data: {
      email: "something@example.com",
      startup: {
        create: {
          id: 1,
          name: "Startup 1",
        },
      },
    },
    select: {
      id: true,
      firstName: true,
      lastName: true,
      email: true,
      startup: true,
      startupId: true,
      validEmail: true,
      scoutingFiles: true,
    },
  });
  console.log(contacts);
};

main()
  .catch((e) => console.log(e))
  .finally(() => prisma.disconnect());
You should see this error:
PrismaClientUnknownRequestError:
Invalid `prisma.contact.create()` invocation in
/Users/siddhant/Code/Tests/experiments/index.ts:6:41

  2
  3 const prisma = new PrismaClient();
  4
  5 const main = async () => {
→ 6   const contacts = await prisma.contact.create(Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: ConversionError(Custom { kind: InvalidData, error: "List field did not return an Array from database. Type identifier was Enum(\"ScoutingFile\"). Value was Boolean(true)." }

   0: backtrace::backtrace::trace
   1: backtrace::capture::Backtrace::new_unresolved
   2: failure::backtrace::internal::InternalBacktrace::new
   3: failure::backtrace::Backtrace::new
   4: <quaint::connector::result_set::result_row::ResultRow as sql_query_connector::row::ToSqlRow>::to_sql_row
   5: <std::future::GenFuture<T> as core::future::future::Future>::poll
   6: <std::future::GenFuture<T> as core::future::future::Future>::poll
   7: std::future::poll_with_tls_context
   8: <std::future::GenFuture<T> as core::future::future::Future>::poll
   9: <std::future::GenFuture<T> as core::future::future::Future>::poll
  10: <std::future::GenFuture<T> as core::future::future::Future>::poll
  11: <std::future::GenFuture<T> as core::future::future::Future>::poll
  12: <std::future::GenFuture<T> as core::future::future::Future>::poll
  13: <std::future::GenFuture<T> as core::future::future::Future>::poll
  14: <std::future::GenFuture<T> as core::future::future::Future>::poll
  15: <std::future::GenFuture<T> as core::future::future::Future>::poll
  16: <std::future::GenFuture<T> as core::future::future::Future>::poll
  17: <std::future::GenFuture<T> as core::future::future::Future>::poll
  18: std::future::poll_with_tls_context
  19: <std::future::GenFuture<T> as core::future::future::Future>::poll
  20: <std::future::GenFuture<T> as core::future::future::Future>::poll
  21: std::panicking::try::do_call
  22: __rust_maybe_catch_panic
  23: <std::future::GenFuture<T> as core::future::future::Future>::poll
  24: <std::future::GenFuture<T> as core::future::future::Future>::poll
  25: <std::future::GenFuture<T> as core::future::future::Future>::poll
  26: hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_catch
  27: <hyper::server::conn::upgrades::UpgradeableConnection<I,S,E> as core::future::future::Future>::poll
  28: <hyper::server::conn::spawn_all::NewSvcTask<I,N,S,E,W> as core::future::future::Future>::poll
  29: tokio::task::core::Core<T>::poll
  30: std::panicking::try::do_call
  31: __rust_maybe_catch_panic
  32: tokio::task::harness::Harness<T,S>::poll
  33: tokio::runtime::thread_pool::worker::GenerationGuard::run_task
  34: tokio::runtime::thread_pool::worker::GenerationGuard::run
  35: std::thread::local::LocalKey<T>::with
  36: tokio::runtime::thread_pool::worker::Worker::run
  37: tokio::task::core::Core<T>::poll
  38: std::panicking::try::do_call
  39: __rust_maybe_catch_panic
  40: tokio::task::harness::Harness<T,S>::poll
  41: tokio::runtime::blocking::pool::Inner::run
  42: tokio::runtime::context::enter
  43: std::sys_common::backtrace::__rust_begin_short_backtrace
  44: std::panicking::try::do_call
  45: __rust_maybe_catch_panic
  46: core::ops::function::FnOnce::call_once{{vtable.shim}}
  47: <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
  48: std::sys::unix::thread::Thread::new::thread_start
  49: _ZL12preoptimized
) })
    at PrismaClientFetcher.message (/Users/siddhant/Code/Tests/experiments/node_modules/@prisma/client/src/runtime/getPrismaClient.ts:649:46)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

So the script above seems to only crash when both startupId & scoutingFIles exist in select. I think this is also a select bug rather than a create bug, because even if you create the records from Postico or something, Client cannot fetch it.

Expected behavior

Script shouldn't crash

Environment & setup

  • OS: macOS
  • Database: Postgres
  • Prisma version:
@prisma/cli          : 2.0.0-beta.5
Current platform     : darwin
Query Engine         : query-engine 0c2ec197653b278b2978845ef958db88824cd82e 
Migration Engine     : migration-engine-cli 0c2ec197653b278b2978845ef958db88824cd82e
Introspection Engine : introspection-core 0c2ec197653b278b2978845ef958db88824cd82e
Format Binary        : prisma-fmt 0c2ec197653b278b2978845ef958db88824cd82e 
  • Node.js version: v12.16.3
@sdnts
Copy link
Contributor Author

sdnts commented May 20, 2020

I should also mention that in all three issues, the DB was originally created with Migrate, so this could actually be an issue with either Migrate or Client.

@sdnts sdnts changed the title findMany fails to select an enum list findMany fails to select an enum list & a relation scalar at the same time May 20, 2020
@janpio
Copy link
Member

janpio commented May 25, 2020

Please add the SQL to the issue, so usage of Migrate is not required to reproduce this.

@janpio janpio added the tech/engines Issue for tech Engines. label May 25, 2020
@janpio janpio added this to the Beta 7 milestone May 25, 2020
@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. labels May 25, 2020
@dpetrick dpetrick self-assigned this May 26, 2020
@dpetrick
Copy link
Contributor

Fixed with 2.0.0-alpha.1205 onwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. tech/engines Issue for tech Engines.
Projects
None yet
Development

No branches or pull requests

3 participants