fix: store trigger targets parsed so rename, list and count see them (#12296)

This commit is contained in:
AlexRV12
2026-11-09 17:05:48 +01:00
committed by GitHub
parent 836440280e
commit ca2440997e
5 changed files with 62 additions and 2 deletions
@@ -0,0 +1 @@
-- Nothing to do here: the stripped `/` named nothing.
@@ -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 '//%';
+11 -2
View File
@@ -247,7 +247,7 @@ pub async fn create_many_http_triggers(
Extension(db): Extension<DB>,
Extension(user_db): Extension<UserDB>,
Path(w_id): Path<String>,
Json(new_http_triggers): Json<Vec<TriggerData<HttpConfigRequest>>>,
Json(mut new_http_triggers): Json<Vec<TriggerData<HttpConfigRequest>>>,
) -> 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)
+2
View File
@@ -557,6 +557,7 @@ async fn create_trigger<T: TriggerCrud>(
}
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<T: TriggerCrud>(
}
edit_trigger.error_handling.validate()?;
edit_trigger.base.normalize_script_path()?;
handler
.validate_edit(&db, &workspace_id, &edit_trigger.config, path)
+14
View File
@@ -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)