diff --git a/backend/src/worker.rs b/backend/src/worker.rs index 82ebc24700..de4e728e7a 100644 --- a/backend/src/worker.rs +++ b/backend/src/worker.rs @@ -1390,7 +1390,6 @@ def main(): assert_eq!(result, serde_json::json!("hello world")); } - #[sqlx::test(fixtures("base"))] async fn test_empty_loop(db: DB) { initialize_tracing().await; @@ -1443,6 +1442,44 @@ def main(): assert_eq!(result, serde_json::json!(0)); } + #[sqlx::test(fixtures("base"))] + async fn test_empty_loop_2(db: DB) { + initialize_tracing().await; + + let flow: FlowValue = serde_json::from_value(serde_json::json!({ + "modules": [ + { + "value": { + "type": "forloopflow", + "iterator": { "type": "static", "value": [] }, + "value": { + "modules": [ + { + "input_transform": { + "n": { + "type": "javascript", + "expr": "previous_result.iter.value", + }, + }, + "value": { + "type": "rawscript", + "language": "python3", + "content": "def main(n): return n", + }, + } + ], + } + }, + }, + ], + })) + .unwrap(); + + let flow = JobPayload::RawFlow { value: flow, path: None }; + let result = run_job_in_new_worker_until_complete(&db, flow).await; + + assert_eq!(result, serde_json::json!([])); + } #[sqlx::test(fixtures("base"))] async fn test_step_after_loop(db: DB) { diff --git a/backend/src/worker_flow.rs b/backend/src/worker_flow.rs index fd5e157c7f..74cf1bbe8b 100644 --- a/backend/src/worker_flow.rs +++ b/backend/src/worker_flow.rs @@ -550,6 +550,24 @@ async fn push_next_flow_job( push_next_flow_job(&new_job, flow, schedule_path, db, json!([])).await?, ); } else { + add_completed_job( + db, + &new_job, + true, + false, + json!([]), + "Forloop completed without iteration".to_string(), + ) + .await?; + postprocess_queued_job( + false, + new_job.schedule_path, + new_job.script_path, + &new_job.workspace_id, + new_job.id, + db, + ) + .await?; return Ok(()); } }