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
Too many records are returned in 4.11.0 when using nested include and @unique field is null #18351
Comments
Thanks for the report @johanforslund, I can reproduce and confirm this. FWIW, I couldn't even recreate your db structure correctly with the latest Prisma since I'll bisect the commit where this starts happening and tag the appropriate people. |
git bisect points at prisma/prisma-engines#3748, cc @tomhoule |
@Weakky could it be the prisma/prisma-engines#3762 problem? |
@tom It does look very similar indeed! |
I realized I had only posted about it in internal slack but not here, but yes, git bisect points at the same commit for that problem too. As a specific example of a query that writes wrong data to the database: await prisma.b.update({
where: {
b1_b2: { b1: 'b11', b2: 'b21' },
},
data: {
cs: {
create: {
c: 'c1',
},
},
},
}) |
@Weakky @tomhoule prisma/prisma-engines#3762 indeed fixes both issues, I just tested it. |
Bug description
We have noticed a bug in Prisma since upgrading from 4.10.1 to 4.11.0. In our database we have a top-down relation between three tables (A->B->C) where the middle table (B) includes an optional
@unique
string. When this field isnull
, it seems to cause issues when Prisma joins the tables onfindUnique
since we get duplicate data from the bottom table (C).The bug disappears if I move the
@unique
constraint from the line where the optional string is declared, and instead place it under my other@@unique
constraints.How to reproduce
Call
findUnique
and include two other tables where the second table includes an optional@unique
constraint. The problem happens when this optional field is null.Expected behavior
No response
Prisma information
The schema looks something like:
I query the data as
This gives me data looking like:
I only expect one element in each of the
cs
arrays.Again, the problem is solved if I change
model B
towhich makes me think that the ordering of the unique constraints matter internally in Prisma. Because it does not work if I do
Environment & setup
Prisma Version
4.11.0
The text was updated successfully, but these errors were encountered: