prisma: `Error: Unknown value type` on nested create
Bug description
After upgrading to prisma v5, we are now seeing the following error when executing a nested create query. We have downgraded to 4.16.2 as a workaround. DEBUG=prisma*
did not yield any more relevant logs for the error. Will attempt to make a small repro.
error - Error: Unknown value type
at pe (/.../node_modules/@prisma/client/runtime/library.js:26:706)
at na (/.../node_modules/@prisma/client/runtime/library.js:115:8408)
at ia (/.../node_modules/@prisma/client/runtime/library.js:115:8562)
at na (/.../node_modules/@prisma/client/runtime/library.js:115:8400)
at ia (/.../node_modules/@prisma/client/runtime/library.js:115:8562)
at na (/.../node_modules/@prisma/client/runtime/library.js:115:8400)
at ia (/.../node_modules/@prisma/client/runtime/library.js:115:8562)
at na (/.../node_modules/@prisma/client/runtime/library.js:115:8400)
at ia (/.../node_modules/@prisma/client/runtime/libra15:8562)
at na (/.../node_modules/@prisma/client/runtime/library.js:115:8400) {
clientVersion: '5.0.0',
How to reproduce
- Run nested create query
Expected behavior
Nested create query succeeds.
Prisma information
datasource db {
provider = "postgres"
url = env("TEST_POSTGRES_URI")
}
generator client {
provider = "prisma-client-js"
output = "../node_modules/.prisma/client"
}
model User {
uuid String @id @default(uuid())
teamUuid String @default(uuid())
userName String
UserTemplateV2 UserTemplateV2[]
}
model UserTemplateV2 {
uuid String @id @default(uuid())
userId String
from String
jsonField Json
user User @relation(fields: [userId], references: [uuid])
}
await prisma.user.create({
select: { uuid: true, teamUuid: true },
data: {
userName: name.trim(),
UserTemplateV2: {
create: [
{
from: `${user.firstName} ${user.lastName}`,
jsonField: { href: new URL("http://www.example.com") }
},
{
from: `${user.firstName} ${user.lastName}`,
jsonField: { href: new URL("http://www.example.com") }
},
],
},
},
});
Environment & setup
- OS: Alpine Linux
- Database: PostgreSQL 14
- Node.js version: v16.19.0
Prisma Version
5.0.0
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 3
- Comments: 23 (9 by maintainers)
Commits related to this issue
- fix: Allow to pass any object with .toJSON column to JSON field That used to work in GraphQL protocol and JS. Technically, it's an "accidental" feature and it does not work on TS level. After some in... — committed to prisma/prisma by SevInf a year ago
- fix: Allow to pass any object with .toJSON method to JSON field That used to work in GraphQL protocol and JS. Technically, it's an "accidental" feature and it does not work on TS level. After some in... — committed to prisma/prisma by SevInf a year ago
- fix: Allow to pass any object with .toJSON method to JSON field (#20259) * fix: Allow to pass any object with .toJSON method to JSON field That used to work in GraphQL protocol and JS. Technically... — committed to prisma/prisma by SevInf a year ago
Hi @Blitz2145 and @masterbater. I know you mentioned that you’ve used workarounds to update your projects, but in case you’d like to revert that in future update, i’d like to let you know that it’s fixed and will be released as a part of Prisma 5.1. If you’d like to test the fix earlier, you can use dev snapshot version
5.1.0-dev.18
. We don’t recommend using in production, but it should be good enough to verify that fix works for you. Thank you!Yea, we just changed our queries to call .toJSON() on the values and we were able to roll-forward to v5.
@wtachau We did not mention in the migration guide because it’s an unexpected bug, which is now fixed and will be included in the next release (5.1.0 scheduled for August 1st).
Oh interesting, I put
in my package.json, re-ran
yarn
andprisma generate
and that’s what got generated. I’ll specify5.1.0-dev.18
exactly later and see if it still happens.This cause error in findUnique, findMany or findFirst when I was passing an ObjectId in id field
Thats why that particular query only causes error, got an idea @Jolg42 and remember ObjectId in mongodb are not string You wont have any issue with this if you only use prisma all throughout your application
@wtachau client version in your error message is
5.1.0-integration-fix-client-types-mixed-input-types.1
, not5.1.0-dev.18
. Please, make sure to update both@prisma/client
andprisma
packages and re-runprisma generate
after doing so.Thanks for the quick fix I was looking on it on your milestone for 5.1 thanks for including it. Props to you and people working on this and all prisma team for your efforts.
We’re looking into this, like @Blitz2145, in the previous versions
.toJSON()
was called byJSON.stringify()
and it worked “unexpectedly” in JS without type-checking.With type-checking it is not possible to have
jsonField: { href: new URL("http://www.example.com/") }
for example.There are 2 options at the moment:
4.16.2
and wait for updates here, we are working on a fix and we’ll share a special version that you will be able to try..toJSON()
, likejsonField: { href: new URL("http://www.example.com/").toJSON() }
Note that nothing needs to be changed for
Date
,Decimal
,BigInt
orBuffer
.@SevInf I’ve updated the description with a schema and query that I think should reproduce the issue. We are passing a URL (https://developer.mozilla.org/en-US/docs/Web/API/URL#instance_methods) value into the json field. Its seems like previously that value was being processed correctly since it implements
toJSON
but maybe that is no longer being called in v5.