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: noop update from selectors should work #4092

Merged
merged 5 commits into from
Jul 31, 2023

Conversation

Weakky
Copy link
Contributor

@Weakky Weakky commented Jul 31, 2023

Overview

Follow-up to #4084. Fixes a regression for 1-1 update when relationMode=prisma.

The PR fixes two things:

  1. Noop updates take selectors into account: In the case of an update with relationMode=prisma, we read the record to update before doing the actual update to compute whether some referential actions will need to be added to the graph. When doing this additional read, we pass the read ids down to the update operation so that we save reading the ids again when the connector does not support UpdateReturning. These ids are passed as RecordFilter.selectors. However, the selectors were not considered when doing a simple read for a noop update. Therefore, the update node wasn't returning the correct ids, leading to failed operations later on.
  2. WriteArgs::returns is now updated to take into account the fact that update nodes can now return more than just the primary identifier of a model. While we haven't noticed any bug, it could've resulted in missing reload nodes when the child of a node is requesting data dependencies that aren't fulfilled by the parent's selection set.

See https://prisma-company.slack.com/archives/C058VM009HT/p1690562457715389

@Weakky Weakky requested a review from a team as a code owner July 31, 2023 11:16
@codspeed-hq
Copy link

codspeed-hq bot commented Jul 31, 2023

CodSpeed Performance Report

Merging #4092 will not alter performance

Comparing integration/fix-1-1-update-relation-mode-prisma (5073e8a) with main (2650ebd)

Summary

✅ 11 untouched benchmarks

Comment on lines +67 to +73
Self::UpdateRecord(UpdateRecord::WithExplicitSelection(ur)) => {
ur.selected_fields.is_superset_of(field_selection)
}
Self::UpdateRecord(UpdateRecord::WithImplicitSelection(ur)) => {
ur.selected_fields().is_superset_of(field_selection)
}
Self::UpdateRecord(UpdateRecord::WithoutSelection(_)) => returns_id,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit out of scope for this PR.

This method, WriteQuery::returns, is used to compute reload nodes by checking whether a node's field selection fulfills its children data dependencies. It had not been updated after making UpdateRecord nodes return an arbitrary selection set. This means that some reload nodes might've not been added in cases it's needed.

Comment on lines +29 to +31
let filter = build_update_one_filter(record_filter);

return get_single_record(conn, model, &filter, &selected_fields, &[], ctx).await;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual fix. The filter generated for the read in the case of a noop update now takes into account the whole RecordFilter, thus rendering a filter for selectors too if any are present.

@Jolg42 Jolg42 added this to the 5.1.0 milestone Jul 31, 2023
@Weakky Weakky merged commit a9b7003 into main Jul 31, 2023
26 checks passed
@Weakky Weakky deleted the integration/fix-1-1-update-relation-mode-prisma branch July 31, 2023 13:48
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.

3 participants