diff --git a/backend/.sqlx/query-b6644bc0d5ba6063dc70444ec538f87ce996ca4c6203feaf8d42c4e1d42e6cbe.json b/backend/.sqlx/query-a66e2cbe2cef129e4f5b7b633a976d880de6a0cc87278498bea95f9370d3574a.json similarity index 72% rename from backend/.sqlx/query-b6644bc0d5ba6063dc70444ec538f87ce996ca4c6203feaf8d42c4e1d42e6cbe.json rename to backend/.sqlx/query-a66e2cbe2cef129e4f5b7b633a976d880de6a0cc87278498bea95f9370d3574a.json index 7ddeb3d0c9..0dbb98f0ed 100644 --- a/backend/.sqlx/query-b6644bc0d5ba6063dc70444ec538f87ce996ca4c6203feaf8d42c4e1d42e6cbe.json +++ b/backend/.sqlx/query-a66e2cbe2cef129e4f5b7b633a976d880de6a0cc87278498bea95f9370d3574a.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT j.id AS \"id!\", j.created_by AS \"created_by!\",\n CASE WHEN a.agent THEN regexp_replace(j.runnable_path, '\\.chat$', '')\n ELSE j.runnable_path END AS runnable_path,\n CASE\n WHEN a.agent THEN 'agent'\n WHEN j.kind IN ('script', 'script_hub', 'unassigned_script', 'preview')\n THEN 'script'\n WHEN j.kind IN ('flow', 'unassigned_flow', 'flowpreview') THEN 'flow'\n WHEN j.kind IN ('singlestepflow', 'unassigned_singlestepflow') THEN\n CASE WHEN COALESCE(\n (SELECT m->'value'->>'type'\n FROM jsonb_array_elements(j.raw_flow->'modules') m\n WHERE m->>'id' IN ('a', 'main')\n LIMIT 1),\n 'script'\n ) = 'flow' THEN 'flow' ELSE 'script' END\n END AS acl_kind\n FROM v2_job j,\n LATERAL (SELECT j.kind = 'flowpreview'\n AND j.raw_flow->'modules'->1 IS NULL\n AND j.raw_flow->'modules'->0->>'id' = '__wm_agent_root' AS agent) a\n WHERE j.id = ANY($1) AND j.workspace_id = $2", + "query": "SELECT s.id AS \"id!\", j.created_by AS \"created_by!\",\n CASE WHEN a.agent THEN regexp_replace(j.runnable_path, '\\.chat$', '')\n ELSE j.runnable_path END AS runnable_path,\n CASE\n WHEN a.agent THEN 'agent'\n WHEN j.kind IN ('script', 'script_hub', 'unassigned_script', 'preview')\n THEN 'script'\n WHEN j.kind IN ('flow', 'unassigned_flow', 'flowpreview') THEN 'flow'\n WHEN j.kind IN ('singlestepflow', 'unassigned_singlestepflow') THEN\n CASE WHEN COALESCE(\n (SELECT m->'value'->>'type'\n FROM jsonb_array_elements(j.raw_flow->'modules') m\n WHERE m->>'id' IN ('a', 'main')\n LIMIT 1),\n 'script'\n ) = 'flow' THEN 'flow' ELSE 'script' END\n END AS acl_kind\n FROM v2_job s\n JOIN v2_job j ON j.id = COALESCE(s.root_job, s.flow_innermost_root_job, s.parent_job, s.id)\n AND j.workspace_id = s.workspace_id,\n LATERAL (SELECT j.kind = 'flowpreview'\n AND j.raw_flow->'modules'->1 IS NULL\n AND j.raw_flow->'modules'->0->>'id' = '__wm_agent_root' AS agent) a\n WHERE s.id = ANY($1) AND s.workspace_id = $2", "describe": { "columns": [ { @@ -37,5 +37,5 @@ null ] }, - "hash": "b6644bc0d5ba6063dc70444ec538f87ce996ca4c6203feaf8d42c4e1d42e6cbe" + "hash": "a66e2cbe2cef129e4f5b7b633a976d880de6a0cc87278498bea95f9370d3574a" } diff --git a/backend/windmill-api/src/jobs.rs b/backend/windmill-api/src/jobs.rs index e197aea3b8..fbd56ef169 100644 --- a/backend/windmill-api/src/jobs.rs +++ b/backend/windmill-api/src/jobs.rs @@ -2418,13 +2418,14 @@ struct JobRunnable { target: Option<(RunnableAclKind, String)>, } -/// One query for all `ids`. A saved agent's run is a flow preview under its path (its chat turns -/// under `.chat`), a script or flow wrapped for retries or an error handler a single-step -/// flow, and a preview's path the label `require_preview_label_runnable` checks; recognized as -/// `require_job_within_read_scope` does. +/// One query for all `ids`. A step of a run (a flow's module, a branch, a workflow-as-code child) +/// stands for the run it belongs to, as only the top level needs run. A saved agent's run is a +/// flow preview under its path (its chat turns under `.chat`), a script or flow wrapped +/// for retries or an error handler a single-step flow, and a preview's path the label +/// `require_preview_label_runnable` checks; recognized as `require_job_within_read_scope` does. async fn job_runnables(db: &DB, w_id: &str, ids: &[Uuid]) -> error::Result> { let rows = sqlx::query!( - r#"SELECT j.id AS "id!", j.created_by AS "created_by!", + r#"SELECT s.id AS "id!", j.created_by AS "created_by!", CASE WHEN a.agent THEN regexp_replace(j.runnable_path, '\.chat$', '') ELSE j.runnable_path END AS runnable_path, CASE @@ -2441,11 +2442,13 @@ async fn job_runnables(db: &DB, w_id: &str, ids: &[Uuid]) -> error::Result'modules'->1 IS NULL AND j.raw_flow->'modules'->0->>'id' = '__wm_agent_root' AS agent) a - WHERE j.id = ANY($1) AND j.workspace_id = $2"#, + WHERE s.id = ANY($1) AND s.workspace_id = $2"#, ids, w_id, )