From 8e3b8bdfd2ded9652bc7e876c6bcd0ac2cfae148 Mon Sep 17 00:00:00 2001 From: wendrul <53628737+wendrul@users.noreply.github.com> Date: Fri, 13 Mar 2026 07:04:44 +0100 Subject: [PATCH] fix: Linked resources and vars not triggering both sync jobs on delete (#8342) * fix: Linked resources and vars not triggering both sync jobs on delete * prepare sqlx --- ...1f7f387f5055c47f493271d26731336257384.json | 10 +++--- ...cc4a4d518093ab48e79365dbb808068e0b8ff.json | 23 +++++++++++++ ...153c43903f929ae5d62fbba12610f89c36d55.json | 2 +- ...8690a44573c1869a206474811215714ba97c2.json | 15 --------- backend/windmill-store/src/resources.rs | 33 ++++++++++++++++--- backend/windmill-store/src/variables.rs | 33 ++++++++++++++++--- 6 files changed, 87 insertions(+), 29 deletions(-) create mode 100644 backend/.sqlx/query-3317484a9c09c07c2c9db9debaecc4a4d518093ab48e79365dbb808068e0b8ff.json delete mode 100644 backend/.sqlx/query-bf2aeb9a1e649106d2a084c1d628690a44573c1869a206474811215714ba97c2.json diff --git a/backend/.sqlx/query-07168aaf14cb6beff0ad4274b441f7f387f5055c47f493271d26731336257384.json b/backend/.sqlx/query-07168aaf14cb6beff0ad4274b441f7f387f5055c47f493271d26731336257384.json index e7ed0aee65..d29a18c691 100644 --- a/backend/.sqlx/query-07168aaf14cb6beff0ad4274b441f7f387f5055c47f493271d26731336257384.json +++ b/backend/.sqlx/query-07168aaf14cb6beff0ad4274b441f7f387f5055c47f493271d26731336257384.json @@ -46,11 +46,11 @@ ] }, "nullable": [ - false, - false, - false, - false, - false, + true, + true, + true, + true, + true, true, true ] diff --git a/backend/.sqlx/query-3317484a9c09c07c2c9db9debaecc4a4d518093ab48e79365dbb808068e0b8ff.json b/backend/.sqlx/query-3317484a9c09c07c2c9db9debaecc4a4d518093ab48e79365dbb808068e0b8ff.json new file mode 100644 index 0000000000..edabfc0be8 --- /dev/null +++ b/backend/.sqlx/query-3317484a9c09c07c2c9db9debaecc4a4d518093ab48e79365dbb808068e0b8ff.json @@ -0,0 +1,23 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM variable WHERE path = $1 AND workspace_id = $2 RETURNING path", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "path", + "type_info": "Varchar" + } + ], + "parameters": { + "Left": [ + "Text", + "Text" + ] + }, + "nullable": [ + false + ] + }, + "hash": "3317484a9c09c07c2c9db9debaecc4a4d518093ab48e79365dbb808068e0b8ff" +} diff --git a/backend/.sqlx/query-5a219a2532517869578c4504ff3153c43903f929ae5d62fbba12610f89c36d55.json b/backend/.sqlx/query-5a219a2532517869578c4504ff3153c43903f929ae5d62fbba12610f89c36d55.json index 36ddb8ab9f..713ccb9dd3 100644 --- a/backend/.sqlx/query-5a219a2532517869578c4504ff3153c43903f929ae5d62fbba12610f89c36d55.json +++ b/backend/.sqlx/query-5a219a2532517869578c4504ff3153c43903f929ae5d62fbba12610f89c36d55.json @@ -15,7 +15,7 @@ ] }, "nullable": [ - true + null ] }, "hash": "5a219a2532517869578c4504ff3153c43903f929ae5d62fbba12610f89c36d55" diff --git a/backend/.sqlx/query-bf2aeb9a1e649106d2a084c1d628690a44573c1869a206474811215714ba97c2.json b/backend/.sqlx/query-bf2aeb9a1e649106d2a084c1d628690a44573c1869a206474811215714ba97c2.json deleted file mode 100644 index 91b4f2786a..0000000000 --- a/backend/.sqlx/query-bf2aeb9a1e649106d2a084c1d628690a44573c1869a206474811215714ba97c2.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "DELETE FROM resource WHERE path = $1 AND workspace_id = $2", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Text", - "Text" - ] - }, - "nullable": [] - }, - "hash": "bf2aeb9a1e649106d2a084c1d628690a44573c1869a206474811215714ba97c2" -} diff --git a/backend/windmill-store/src/resources.rs b/backend/windmill-store/src/resources.rs index 6b414ca10f..8d5ba23b67 100644 --- a/backend/windmill-store/src/resources.rs +++ b/backend/windmill-store/src/resources.rs @@ -891,12 +891,12 @@ async fn delete_resource( .fetch_optional(&mut *tx) .await?; not_found_if_none(deleted_path, "Resource", &path)?; - sqlx::query!( - "DELETE FROM variable WHERE path = $1 AND workspace_id = $2", + let deleted_linked_variable = sqlx::query_scalar!( + "DELETE FROM variable WHERE path = $1 AND workspace_id = $2 RETURNING path", path, w_id ) - .execute(&mut *tx) + .fetch_optional(&mut *tx) .await?; audit_log( &mut *tx, @@ -924,9 +924,34 @@ async fn delete_resource( webhook.send_message( w_id.clone(), - WebhookMessage::DeleteResource { workspace: w_id, path: path.to_owned() }, + WebhookMessage::DeleteResource { workspace: w_id.clone(), path: path.to_owned() }, ); + if deleted_linked_variable.is_some() { + handle_deployment_metadata( + &authed.email, + &authed.username, + &db, + &w_id, + DeployedObject::Variable { + path: path.to_string(), + parent_path: Some(path.to_string()), + }, + Some(format!( + "Variable '{}' deleted (linked resource deleted)", + path + )), + true, + None, + ) + .await?; + + webhook.send_message( + w_id.clone(), + WebhookMessage::DeleteVariable { workspace: w_id, path: path.to_owned() }, + ); + } + Ok(format!("resource {} deleted", path)) } diff --git a/backend/windmill-store/src/variables.rs b/backend/windmill-store/src/variables.rs index 233115896f..aedd22e7ce 100644 --- a/backend/windmill-store/src/variables.rs +++ b/backend/windmill-store/src/variables.rs @@ -536,12 +536,12 @@ async fn delete_variable( ) .execute(&mut *tx) .await?; - sqlx::query!( - "DELETE FROM resource WHERE path = $1 AND workspace_id = $2", + let deleted_linked_resource = sqlx::query_scalar!( + "DELETE FROM resource WHERE path = $1 AND workspace_id = $2 RETURNING path", path, w_id ) - .execute(&mut *tx) + .fetch_optional(&mut *tx) .await?; audit_log( &mut *tx, @@ -575,9 +575,34 @@ async fn delete_variable( webhook.send_message( w_id.clone(), - WebhookMessage::DeleteVariable { workspace: w_id, path: path.to_owned() }, + WebhookMessage::DeleteVariable { workspace: w_id.clone(), path: path.to_owned() }, ); + if deleted_linked_resource.is_some() { + handle_deployment_metadata( + &authed.email, + &authed.username, + &db, + &w_id, + DeployedObject::Resource { + path: path.to_string(), + parent_path: Some(path.to_string()), + }, + Some(format!( + "Resource '{}' deleted (linked variable deleted)", + path + )), + true, + None, + ) + .await?; + + webhook.send_message( + w_id.clone(), + WebhookMessage::DeleteResource { workspace: w_id, path: path.to_owned() }, + ); + } + Ok(format!("variable {} deleted", path)) }