diff --git a/Cargo.lock b/Cargo.lock index 79bed9b09f4c..45a24ba164ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2259,7 +2259,7 @@ checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" [[package]] name = "mysql_async" version = "0.30.0" -source = "git+https://github.com/prisma/mysql_async?branch=vendored-openssl#e3f8bdb41d57e769412f53d0f479bf67fdcc0ee3" +source = "git+https://github.com/prisma/mysql_async?branch=vendored-openssl#b5d16fb211fc6a0d5c892269536a95da803eabae" dependencies = [ "bytes", "crossbeam", diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/mod.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/mod.rs index c8768e1325e0..85e9f087f93d 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/mod.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/mod.rs @@ -15,6 +15,7 @@ mod prisma_15264; mod prisma_15467; mod prisma_15581; mod prisma_15607; +mod prisma_17103; mod prisma_5952; mod prisma_6173; mod prisma_7010; diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_17103.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_17103.rs new file mode 100644 index 000000000000..51dc782ce363 --- /dev/null +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_17103.rs @@ -0,0 +1,44 @@ +use indoc::indoc; +use query_engine_tests::*; + +#[test_suite(schema(schema))] +mod prisma_17103 { + fn schema() -> String { + let schema = indoc! { + r#"model A { + #id(id, Int, @id) + + b B? @relation(fields: [bId], references: [id]) + bId Int? + } + + model B { + #id(id, Int, @id) + a A[] + } + "# + }; + + schema.to_owned() + } + + #[connector_test] + async fn regression(runner: Runner) -> TestResult<()> { + run_query!( + &runner, + r#"mutation { + createOneA(data: { id: 1, b: { create: { id: 1 } } }) { + id + } + } + "# + ); + + insta::assert_snapshot!( + run_query!(&runner, r#"mutation { updateOneB(where: { id: 1 }, data: { a: { connect: { id: 1 } } }) { id } }"#), + @r###"{"data":{"updateOneB":{"id":1}}}"### + ); + + Ok(()) + } +} diff --git a/query-engine/connectors/mongodb-query-connector/src/root_queries/write.rs b/query-engine/connectors/mongodb-query-connector/src/root_queries/write.rs index 5a7f93a54963..9655958beefd 100644 --- a/query-engine/connectors/mongodb-query-connector/src/root_queries/write.rs +++ b/query-engine/connectors/mongodb-query-connector/src/root_queries/write.rs @@ -210,7 +210,10 @@ pub async fn update_records<'conn>( .instrument(span) .await?; - if update_type == UpdateType::Many && res.modified_count == 0 { + // It's important we check the `matched_count` and not the `modified_count` here. + // MongoDB returns `modified_count: 0` when performing a noop update, which breaks + // nested connect mutations as it rely on the returned count to know whether the update happened. + if update_type == UpdateType::Many && res.matched_count == 0 { return Ok(Vec::new()); } } diff --git a/query-engine/connectors/sql-query-connector/src/database/operations/write.rs b/query-engine/connectors/sql-query-connector/src/database/operations/write.rs index 4dc9b83c765d..c5680ba35ac9 100644 --- a/query-engine/connectors/sql-query-connector/src/database/operations/write.rs +++ b/query-engine/connectors/sql-query-connector/src/database/operations/write.rs @@ -363,7 +363,7 @@ async fn update_records_from_filter( ctx: &Context<'_>, ) -> crate::Result { let update = build_update_and_set_query(model, args, ctx); - let filter_condition = record_filter.clone().filter.aliased_condition_from(None, false, ctx); + let filter_condition = record_filter.filter.aliased_condition_from(None, false, ctx); let update = update.so_that(filter_condition); let count = conn.execute(update.into()).await?;