Skip to content

Commit 9fb012f

Browse files
authored
fix: include read parent for non-UpdateReturning dbs (#5498)
Makes prisma/prisma#27489 tests pass. This change fixes updates in MySQL with the query compiler. Before this change, the graphs did not have a read node connected to the update node, which is incorrect for databases with no support for `RETURNING`. It worked fine with Planetscale because the read node was being inserted due to the relation mode being set to Prisma. It also worked fine in the query engine, because the query engine dynamically dispatches queries at runtime whenever an update in the graph is missing selectors - we can't do that at runtime in the query interpreter though, so the graph creation needs to be adjusted.
1 parent 63298ba commit 9fb012f

2 files changed

Lines changed: 8 additions & 19 deletions

File tree

query-engine/core/src/query_ast/write.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,6 @@ impl UpdateRecord {
330330
UpdateRecord::WithoutSelection(_) => None,
331331
}
332332
}
333-
334-
pub(crate) fn set_record_filter(&mut self, record_filter: RecordFilter) {
335-
match self {
336-
UpdateRecord::WithSelection(u) => u.record_filter = record_filter,
337-
UpdateRecord::WithoutSelection(u) => u.record_filter = record_filter,
338-
}
339-
}
340333
}
341334

342335
#[derive(Debug, Clone)]

query-engine/core/src/query_graph_builder/write/update.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::*;
2-
use crate::inputs::RecordQueryFilterInput;
2+
use crate::inputs::{RecordQueryFilterInput, UpdateRecordSelectorsInput};
33
use crate::query_graph_builder::write::limit::validate_limit;
44
use crate::query_graph_builder::write::write_args_parser::*;
55
use crate::{
@@ -39,27 +39,23 @@ pub(crate) fn update_record(
3939
Some(&field),
4040
)?;
4141

42-
if query_schema.relation_mode().is_prisma() {
42+
if !query_schema.has_capability(ConnectorCapability::UpdateReturning) || query_schema.relation_mode().is_prisma() {
4343
let read_parent_node = graph.create_node(utils::read_id_infallible(
4444
model.clone(),
4545
model.shard_aware_primary_identifier(),
46-
filter,
46+
filter.clone(),
4747
));
4848

49-
utils::insert_emulated_on_update(graph, query_schema, &model, &read_parent_node, &update_node)?;
49+
if query_schema.relation_mode().is_prisma() {
50+
utils::insert_emulated_on_update(graph, query_schema, &model, &read_parent_node, &update_node)?;
51+
}
5052

5153
graph.create_edge(
5254
&read_parent_node,
5355
&update_node,
54-
QueryGraphDependency::ProjectedDataDependency(
56+
QueryGraphDependency::ProjectedDataSinkDependency(
5557
model.shard_aware_primary_identifier(),
56-
Box::new(move |mut update_node, parent_ids| {
57-
if let Node::Query(Query::Write(WriteQuery::UpdateRecord(ref mut ur))) = update_node {
58-
ur.set_record_filter(parent_ids.into());
59-
}
60-
61-
Ok(update_node)
62-
}),
58+
RowSink::All(&UpdateRecordSelectorsInput),
6359
Some(DataExpectation::non_empty_rows(
6460
MissingRecord::builder().operation(DataOperation::Update).build(),
6561
)),

0 commit comments

Comments
 (0)