prisma: uncheckedScalarInputs: XOR not working?
Bug description
The XOR functionality to allow either unchecked scalars xor regular prisma relations doesn’t appear to be working for me
the function:
export const createInvestor = ({ input: { companyId, email } }) => {
return db.investor.create({
data: {
company: {
connect: { id: companyId },
},
investor: {
connectOrCreate: {
where: { email },
create: { email },
},
},
},
})
}
the error:
api | Error:
api | Invalid `prisma.investor.create()` invocation:
api |
api | {
api | data: {
api | company: {
api | ~~~~~~~
api | connect: {
api | where: {
api | companyId: 'dc7085fb-62e0-405c-bb0f-a4d33fa6bcae'
api | }
api | }
api | },
api | investor: {
api | ~~~~~~~~
api | connectOrCreate: {
api | where: {
api | email: 'test@gmail.com'
api | },
api | create: {
api | email: 'test@gmail.com'
api | }
api | }
api | },
api | + investorId: String,
api | + companyId: String,
api | ? createdAt?: DateTime,
api | ? updatedAt?: DateTime
api | }
api | }
api |
api | Unknown arg `company` in data.company for type InvestorUncheckedCreateInput. Did you mean `companyId`?
api | Unknown arg `investor` in data.investor for type InvestorUncheckedCreateInput. Did you mean `investorId`?
api | Argument investorId for data.investorId is missing.
api | Argument companyId for data.companyId is missing.
Expected behavior
Prisma should recognize I’m not using unchecked scalars
Prisma information
model Investor {
investor User @relation(fields: [investorId], references: [id])
investorId String
company Company @relation(fields: [companyId], references: [id])
companyId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@id([investorId, companyId])
}
Environment & setup
- OS: MacOS 10.15.5
- Database: Postgres 12.5
- Node.js version: 14.15.4
- Prisma version: 2.11.0 [used through redwoodjs]
- Redwood version: 0.23
Happy to provide further information if helpful, have not yet tried to re-create in a minimal repo
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 26 (5 by maintainers)
I just upgraded to 2.15 and Creates & Updates that were previously working started hitting the types <type>Unchecked<Create/Update>Input instead of expected <type><Create/Update>Input (so for example ContactPersonUncheckedUpdateInput when I’m providing data that matches ContactPersonUpdateInput.)
At first I though I had the same issue, but turns out it was actually an error on my part, causing to a bit misleading error message! So read further to check if that’s the case with you as well
Here’s some details.
prisma.schema:
Log
prisma client index.ts:
…but what had really happened that I had just refactored the Company ID to be Int instead of String, but was still providing a String in one place - causing the XOR to not match ContactPersonCreateInput, and fall back to the ContactPersonUncheckedCreateInput, leaving me on a goose hunt googling, finding this error and thinking I had the same case. 😄
So changing the prisma.create call’s data from String
Company = { connect: '12345' }to number (as expected in CompanyWhereUniqueInput)Company = { connect: 12345 }caused the XOR to match the correct input type, and fixed the matter for me.So, in case you encounter this error double check that you’re feeding the exactly right types first, since the error message is currently bit misleading.
Anyone found a way to disable this “uncheckedScalarInputs” feature totally? (since it’s not a switchable preview feature anymore since 2.15).
Or how to force using the Checked models only, I think it was mentioned in some discussion but couldn’t find instructions for it in the Prisma docs yet.
I personally don’t really see any benefit to them in my current project (I’m totally happy doing “Object: { connect: { id: id } }” instead of “objectId: id”), and they are really making debugging the actual models a PITA since the error messages are all wrong.
Hi @timsuchanek!
I think I’m running with this exact same issue.
This is the error I get when I try to create a Post.
Weirdly enough, I’m able to Update a post with categories, but can’t Create.
Here are the informations related to the Create Post:
Create Post
Types in Prisma’s
index.d.ts:Mutation:
Update Post
Types in Prisma’s
index.d.ts:Mutation:
And here is the Model Schema:
I can’t understand why this is working in Update and not on Create when both Types are the same regarding to the
categoriesfield. Maybe I’m doing something obviously wrong. Can someone help me out?@wminshew there is not. But in my experience when I got runtime error messages like the log from thrant I made a mistake in my code somewhere in the nested objects (i.e. using the wrong key) which can be confusing, since the error messages show the highlight the mistake in the highest layer
Best open a new issue with a full description of your situation and including the filled out issue template - much easier for us to handle @jagoncalves14 - thanks.
I am also having this issue. It defaults to assuming I’m using the unchecked type instead of the checked type.
this is my schema
getting this error
from what I’ve seen elsewhere, if you have any error in your types it’ll only flag the first type of the XOR in the message (which, as you’ve noted, is unfortunately not very helpful)
In your case, I think the issue might be that you’re missing a
connectorcreateorconnectOrCreate. I would expect the below to work:related to your last point, yes I don’t think these types are usable as DTOs
@nsebs nothing to bother, that’s a good question! Could you create a separate issue please? Because it seems unrelated to this one.
Yes, exactly.
Sorry about the noise in this issue.
After reading more of the docs I realized that I was trying to use the types in the wrong way:
https://www.prisma.io/docs/concepts/components/prisma-client/working-with-generated-types#problem-using-variations-of-the-generated-model-type
The
PostUpdateInputandPostCreateInputare misleading because they’re not going to contain the relation withcategoriesbecause is not include by default, even when it’s explicit on the signature of the type 😕Which means that we cannot use the generated types as DTOs 😞
I’m having the same problem. I’m using NestJS.
This is the schema (part)
This are the generated types:
This is the controller:
And this is the error thrown by prisma:
Prisma env:
I made this project to check if the error can be reproduced and I’m always able to reproduce it when trying to create or update a model with a many-to-many relation, regardless of how that relation is defined (implicit, explicit, with or without the
@relation()attribute).