Add support for conditional blocks when running with script caching (#4603)

This commit is contained in:
pedrohsdb
2026-02-02 12:30:05 -08:00
committed by GitHub
parent 2409df7589
commit b463272335
3 changed files with 191 additions and 25 deletions

View File

@@ -4,6 +4,7 @@ import hashlib
import importlib.util
import json
import os
import re
import uuid
from dataclasses import dataclass
from datetime import datetime
@@ -2026,7 +2027,17 @@ async def run_script(
context.workflow_run_id = workflow_run_id
context.organization_id = organization_id
# run the script as subprocess; pass the parameters and run_id to the script
# Check if script contains conditional blocks (not supported in CLI execution)
# The marker "# === CONDITIONAL:" is generated by _build_block_statement() for conditional blocks.
with open(path, encoding="utf-8") as f:
script_content = f.read()
if re.search(r"# === CONDITIONAL:", script_content):
raise Exception(
"This script contains conditional blocks which are not supported in CLI execution. "
"Conditional blocks require the workflow engine's DAG traversal to properly evaluate "
"branch conditions at runtime. Please run this workflow through the API instead."
)
# Dynamically import the script at the given path
spec = importlib.util.spec_from_file_location("user_script", path)
if not spec or not spec.loader: