empty Json[]
fields turn to null
(instead of an empty []
) when accessed through a join using the new relationJoins
feature #22923
Description
Bug description
Hey guys, I found a pretty concrete bug that unfortunately blocks our adoption of the relational joins.
Basically, if you have a JSON[] field on a model, and you query that model directly, it resolves as an empty array or a populated array ( as it should). However, when you query that model through a join the empty Json[] fields resolve to null :O This breaks the typings, and the projects client side, because we often try to read .length of the presumed empty arrays.
Even more concrete example:
model Profile {
id: Int
userId: String
links: Json[]
}
model User {
id: String
profile: Profile
}
Querying profile alone resolves correctly with links as [].
Querying User joined with Profile resolves with links to NULL (again, assuming they have not been populated).
Changing the relationLoadStrategy to "query" resolves the issue for now.
What do you guys think? Easy fix?
How to reproduce
- Have two models that are related to each other
- The second one has a Json[] field
- Try to access that field through a join from the first model
Expected behavior
Empty Json[] fields should return an empty [] like they used to
Prisma information
model User {
id String @id @default(cuid())
name String // needed for next auth (I think)
email String @unique
profile Profile?
}
model Profile {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
featuredLinks Json[] // {title: string, description: string, url: string, imageUrl: string}[]
userId String @unique
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
In a React Server Component, but also reproduced this in a regular ts file with tsx and node
let userWithProfile = await prisma.user.findUnique({
where: {
id: id,
},
include: {
profile: true
},
});
Environment & setup
- OS: Mac locally and presumably linux (Vercel cloud functions)
- Database: PostgreSQL(Supabase)
- Node.js version: 18.18 locally
Prisma Version
^5.8.0 (as in anything above 5.7.1, including 5.9)