prisma: Relations not being picked up during create statement

Bug description

Our createUser() function has stopped working, erroring that we aren’t providing an institutionUid when we are using the connect func. Prisma reports it is using UserUncheckedCreateInput, which doesn’t have the relations beyond the uid. Not sure why this is now the default.

(I noticed @matthewmueller closed off uncheckedScalarInputs as stable 4 hours ago, not sure if a change has been made during that time or if that’s just a coincidence).

How to reproduce

  1. Run a prisma.[table-goes-here].create({}) query with a connection, such as:
institution: {
  connect: {
    institutionUid: institutionToAdd.institutionUid,
  },
},
  1. Errors

Expected behavior

The query to succeed.

Prisma information

PrismaClientValidationError: 
Invalid `prisma.user.create()` invocation:

{
  include: {
    institution: true,
  },
  data: {
    userUid: '374174ea-2204-4a62-b033-9795a3fc31b3',
    institution: {
    ~~~~~~~~~~~
      connect: {
        institutionUid: 'df25802e-6cf5-4c21-bafc-141e2c296d58'
      }
    },
+   institutionUid: String,
  }
}

Unknown arg `institution` in data.institution for type UserUncheckedCreateInput. Did you mean `institutionUid`?
Argument institutionUid for data.institutionUid is missing.

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: v12.18.1 (using ts-node version 8.10.2, typescript version 3.9.7)
  • Prisma version:
prisma               : 2.17.0
@prisma/client       : 2.16.1
Current platform     : darwin
Query Engine         : query-engine 3c463ebd78b1d21d8fdacdd27899e280cf686223 (at ../../../.config/yarn/global/node_mo
dules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli 3c463ebd78b1d21d8fdacdd27899e280cf686223 (at ../../../.config/yarn/global
/node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 3c463ebd78b1d21d8fdacdd27899e280cf686223 (at ../../../.config/yarn/global/n
ode_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt 3c463ebd78b1d21d8fdacdd27899e280cf686223 (at ../../../.config/yarn/global/node_modu
les/@prisma/engines/prisma-fmt-darwin)
Studio               : 0.353.0

(edit: realised my prisma versions were out of sync so updated the client to 2.17.0, same issue persists)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 26 (9 by maintainers)

Most upvoted comments

I’ve just verified in my own codebase, if one of the fields is using the format of postId instead of post:{connect:{id}} then it will automatically switch into unchecked mode. Once it switched into unchecked mode, then we’re not able to use the connect checked method anymore. Hence to use the checked mode, we need to switch all to use the checked method.

@lucasjohnston I’m having the same issue

I have the same issue

Can anyone share a minimal example with nexus for a reproduction?

I have the same issue…

Yeah - I’m guessing that conditional isn’t behaving as intended.

// If the inputs are equal, only use one.
  if checked_input == unchecked_input {
      vec![checked_input]
  } else {
      vec![checked_input, unchecked_input]
  }

I don’t understand why the checked_update_many_input_type() and unchecked_update_many_input_type() functions are both supposed to return the same result on a Model for the Client to validate references as checked.

Given it seems to be just us experiencing this (not many ppl are interacting with this issue) it would be useful to get more context about the logic of this function so I can attempt to debug what’s happening. Do you have any unit tests for create_objects.rs that I can use to attempt repro? (cc @dpetrick)

Not sure how prisma automatically switches between Input and UncheckedInput (navigating prisma’s codebase is intimidating 😳) but I presume there’s a piece of logic failing with schema.

Happy to share more detailed schema privately if it’ll help with debugging. We’re on Postgres, using soft-delete middleware (as per the docs), as well as prisma migrations. We also have a second prisma environment which generates custom schema on the fly for Jest tests.

An easy stopgap could be to add a NoUncheckedInput flag or similar in schema.prisma ?

Thanks for the writeup @asciant

Hey everyone, I came across this error in my own application and believe that it is not a Prisma bug, but potentially a typing issue in our applications.

I created a repo to provide a little more information and some examples.

https://github.com/asciant/prisma2-unchecked-relations

Essentially, you will encounter issues like this (particularly when connecting 1-n or m-n relations) if your types don’t match the input types that Prisma is using when creating, or updating. The types can be found in ./node_modules/.prisma/client/index.d.ts and personally, I symlink this file to my main application directory because it’s handy to refer to when issues arise.

Anyway, hopefully this helps anyone in future who comes across this like I did.