From ca2440997e6a9150347ba2856010f11d995dcefb Mon Sep 17 00:00:00 2001 From: AlexRV12 <71396855+AlexRV12@users.noreply.github.com> Date: Mon, 9 Nov 2026 17:05:48 +0100 Subject: [PATCH] fix: store trigger targets parsed so rename, list and count see them (#12296) --- ...31_normalize_trigger_target_paths.down.sql | 1 + ...5931_normalize_trigger_target_paths.up.sql | 34 +++++++++++++++++++ backend/windmill-trigger-http/src/handler.rs | 13 +++++-- backend/windmill-trigger/src/handler.rs | 2 ++ backend/windmill-trigger/src/types.rs | 14 ++++++++ 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 backend/migrations/20261109085931_normalize_trigger_target_paths.down.sql create mode 100644 backend/migrations/20261109085931_normalize_trigger_target_paths.up.sql diff --git a/backend/migrations/20261109085931_normalize_trigger_target_paths.down.sql b/backend/migrations/20261109085931_normalize_trigger_target_paths.down.sql new file mode 100644 index 0000000000..8bc39341e4 --- /dev/null +++ b/backend/migrations/20261109085931_normalize_trigger_target_paths.down.sql @@ -0,0 +1 @@ +-- Nothing to do here: the stripped `/` named nothing. diff --git a/backend/migrations/20261109085931_normalize_trigger_target_paths.up.sql b/backend/migrations/20261109085931_normalize_trigger_target_paths.up.sql new file mode 100644 index 0000000000..2e6ca70ff4 --- /dev/null +++ b/backend/migrations/20261109085931_normalize_trigger_target_paths.up.sql @@ -0,0 +1,34 @@ +-- A trigger's target is compared with a renamed runnable's old path and with the path a runnable +-- lists its triggers by, neither of which starts with `/`. A target with more than one leading `/` +-- names nothing and is left as is: firing the trigger refuses it. +UPDATE http_trigger SET script_path = substr(script_path, 2) +WHERE script_path LIKE '/%' AND script_path NOT LIKE '//%'; +UPDATE email_trigger SET script_path = substr(script_path, 2) +WHERE script_path LIKE '/%' AND script_path NOT LIKE '//%'; +UPDATE websocket_trigger SET script_path = substr(script_path, 2) +WHERE script_path LIKE '/%' AND script_path NOT LIKE '//%'; +UPDATE kafka_trigger SET script_path = substr(script_path, 2) +WHERE script_path LIKE '/%' AND script_path NOT LIKE '//%'; +UPDATE postgres_trigger SET script_path = substr(script_path, 2) +WHERE script_path LIKE '/%' AND script_path NOT LIKE '//%'; +UPDATE mqtt_trigger SET script_path = substr(script_path, 2) +WHERE script_path LIKE '/%' AND script_path NOT LIKE '//%'; +UPDATE nats_trigger SET script_path = substr(script_path, 2) +WHERE script_path LIKE '/%' AND script_path NOT LIKE '//%'; +UPDATE sqs_trigger SET script_path = substr(script_path, 2) +WHERE script_path LIKE '/%' AND script_path NOT LIKE '//%'; +UPDATE amqp_trigger SET script_path = substr(script_path, 2) +WHERE script_path LIKE '/%' AND script_path NOT LIKE '//%'; +UPDATE gcp_trigger SET script_path = substr(script_path, 2) +WHERE script_path LIKE '/%' AND script_path NOT LIKE '//%'; +UPDATE azure_trigger SET script_path = substr(script_path, 2) +WHERE script_path LIKE '/%' AND script_path NOT LIKE '//%'; +-- A restore puts the trashed row back as saved, so the copies awaiting one get the same fix. +UPDATE trashbin +SET item_data = jsonb_set(item_data, '{row,script_path}', + to_jsonb(substr(item_data #>> '{row,script_path}', 2))) +WHERE item_data ->> 'table_name' IN ('http_trigger', 'email_trigger', 'websocket_trigger', + 'kafka_trigger', 'postgres_trigger', 'mqtt_trigger', 'nats_trigger', 'sqs_trigger', + 'amqp_trigger', 'gcp_trigger', 'azure_trigger') + AND item_data #>> '{row,script_path}' LIKE '/%' + AND item_data #>> '{row,script_path}' NOT LIKE '//%'; diff --git a/backend/windmill-trigger-http/src/handler.rs b/backend/windmill-trigger-http/src/handler.rs index 539c8e43d2..21caab6e7c 100644 --- a/backend/windmill-trigger-http/src/handler.rs +++ b/backend/windmill-trigger-http/src/handler.rs @@ -247,7 +247,7 @@ pub async fn create_many_http_triggers( Extension(db): Extension, Extension(user_db): Extension, Path(w_id): Path, - Json(new_http_triggers): Json>>, + Json(mut new_http_triggers): Json>>, ) -> Result<(StatusCode, String)> { // Admin check for instance-wide routes is done per-trigger in insert_new_trigger_into_db @@ -264,7 +264,7 @@ pub async fn create_many_http_triggers( let mut route_path_keys = Vec::with_capacity(new_http_triggers.len()); - for new_http_trigger in new_http_triggers.iter() { + for new_http_trigger in new_http_triggers.iter_mut() { // Per-item write scope, matching the single-create handler. The bulk // endpoint must not let a path-scoped token create triggers outside it. check_scopes(&authed, || { @@ -280,6 +280,15 @@ pub async fn create_many_http_triggers( new_http_trigger.config.route_path, err )) })?; + new_http_trigger + .base + .normalize_script_path() + .map_err(|err| { + Error::BadRequest(format!( + "Error occurred for HTTP route at route path: {}, error: {}", + new_http_trigger.config.route_path, err + )) + })?; handler .validate_new(&db, &w_id, &new_http_trigger.config) diff --git a/backend/windmill-trigger/src/handler.rs b/backend/windmill-trigger/src/handler.rs index fec3180801..3d7a4ea385 100644 --- a/backend/windmill-trigger/src/handler.rs +++ b/backend/windmill-trigger/src/handler.rs @@ -557,6 +557,7 @@ async fn create_trigger( } new_trigger.error_handling.validate()?; + new_trigger.base.normalize_script_path()?; handler .validate_new(&db, &workspace_id, &new_trigger.config) @@ -829,6 +830,7 @@ async fn update_trigger( } edit_trigger.error_handling.validate()?; + edit_trigger.base.normalize_script_path()?; handler .validate_edit(&db, &workspace_id, &edit_trigger.config, path) diff --git a/backend/windmill-trigger/src/types.rs b/backend/windmill-trigger/src/types.rs index dfcc793fa4..e99f35fe1e 100644 --- a/backend/windmill-trigger/src/types.rs +++ b/backend/windmill-trigger/src/types.rs @@ -211,6 +211,20 @@ impl BaseTriggerData { self.mode = Some(mode); } + /// Stored as parsed: a rename retargets triggers, and a runnable lists its own, by exact + /// `script_path`, so one saved with a leading `/` would run but be missed by both. Empty is + /// left alone: a static HTTP route has no runnable. + pub fn normalize_script_path(&mut self) -> windmill_common::error::Result<()> { + if self.script_path.is_empty() { + return Ok(()); + } + self.script_path = + windmill_common::runnable_ref::RunnableRef::from_path(&self.script_path, self.is_flow)? + .path() + .to_string(); + Ok(()) + } + pub fn resolve_permissioned_as(&self, authed: &impl Authable) -> String { if let Some(ref permissioned_as) = self.permissioned_as { if self.preserve_permissioned_as.unwrap_or(false)