fix: move draft and template context handling out of create_workflow_run

create_workflow_run now only creates
the run with the definition_id and initial_context provided by the caller. Test call paths explicitly resolve draft definitions
and merge template context variables before creating the run, while production/runtime paths bind the published definition
without adding template defaults.
This commit is contained in:
Sabiha Khan 2026-07-18 19:00:32 +05:30
parent f69ab294af
commit c2541d088b
18 changed files with 552 additions and 75 deletions

View file

@ -51,6 +51,7 @@ from api.services.workflow.run_usage_response import (
format_public_cost_info,
format_public_usage_info,
)
from api.services.workflow.run_creation import prepare_workflow_run_inputs
from api.services.workflow.trigger_paths import (
TriggerPathIssue,
ensure_trigger_paths,
@ -1302,13 +1303,27 @@ async def create_workflow_run(
request: The create workflow run request
user: The user to create the workflow run for
"""
workflow = await db_client.get_workflow(
workflow_id, organization_id=user.selected_organization_id
)
if not workflow:
raise HTTPException(status_code=404, detail="Workflow not found")
run_inputs = await prepare_workflow_run_inputs(
db_client,
workflow,
use_draft=True,
include_template_context=True,
)
run = await db_client.create_workflow_run(
request.name,
workflow_id,
request.mode,
user.id,
use_draft=True,
organization_id=user.selected_organization_id,
definition_id=run_inputs.definition_id,
initial_context=run_inputs.initial_context,
)
return {
"id": run.id,