Skip to content
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

fix: atomic updates should always do a select with nested operations #4100

Merged
merged 3 commits into from
Aug 2, 2023

Conversation

Weakky
Copy link
Member

@Weakky Weakky commented Aug 2, 2023

Overview

fixes prisma/prisma#20491

Before this PR, the following query:

mutation {
  updateOnePost(
    where: { id: 1 },
    data: {
      author: { update: { id: 42 } }
    }) {
    id
    authorId
  }
}

Would result in the following SQL queries:

BEGIN
SELECT id, authorId FROM "Post" WHERE id = 1;
UPDATE "User" SET id = 42 WHERE id = 1;
COMMIT

Where the first SELECT would be used as the result. Unfortunately in this case (and other cases such as with a disconnect or delete), the nested update alters the foreign key and so the returned authorId would not reflect the actual update.

For this reason (and for simplicity atm), we've decided to bring back the post SELECT as soon as there are any nested mutations in an update. Therefore, the client query above will now result in the following SQL queries:

BEGIN
SELECT id, authorId FROM "Post" WHERE id = 1;
UPDATE "User" SET id = 42 WHERE id = 1;
SELECT id, authorId FROM "Post" WHERE id = 1;
COMMIT

@Weakky Weakky requested a review from a team as a code owner August 2, 2023 13:35
@Jolg42 Jolg42 added this to the 5.2.0 milestone Aug 2, 2023
@codspeed-hq
Copy link

codspeed-hq bot commented Aug 2, 2023

CodSpeed Performance Report

Merging #4100 will not alter performance

Comparing fix/to-one-fks-update (797b093) with main (a9b7003)

Summary

✅ 11 untouched benchmarks

@Weakky Weakky merged commit 4ff176d into main Aug 2, 2023
4 checks passed
@Weakky Weakky deleted the fix/to-one-fks-update branch August 2, 2023 14:25
@Weakky Weakky removed this from the 5.2.0 milestone Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prisma Client: disconnect: true does not appear to delete the foreign key in the returned data
3 participants