Skip to content

Commit a84c557

Browse files
fix(workflow-in-workflow): variables not accessible in child workflow (#783)
* fix(workflow-in-workflow): child workflow must be able to access vars * simplify
1 parent 5ddfe1b commit a84c557

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

apps/sim/app/api/workflows/[id]/execute/route.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -264,24 +264,13 @@ async function executeWorkflow(workflow: any, requestId: string, input?: any): P
264264
{} as Record<string, Record<string, any>>
265265
)
266266

267-
// Get workflow variables
268-
let workflowVariables = {}
269-
if (workflow.variables) {
270-
try {
271-
// Parse workflow variables if they're stored as a string
272-
if (typeof workflow.variables === 'string') {
273-
workflowVariables = JSON.parse(workflow.variables)
274-
} else {
275-
// Otherwise use as is (already parsed JSON)
276-
workflowVariables = workflow.variables
277-
}
278-
logger.debug(
279-
`[${requestId}] Loaded ${Object.keys(workflowVariables).length} workflow variables for: ${workflowId}`
280-
)
281-
} catch (error) {
282-
logger.error(`[${requestId}] Failed to parse workflow variables: ${workflowId}`, error)
283-
// Continue execution even if variables can't be parsed
284-
}
267+
// Get workflow variables - they are stored as JSON objects in the database
268+
const workflowVariables = (workflow.variables as Record<string, any>) || {}
269+
270+
if (Object.keys(workflowVariables).length > 0) {
271+
logger.debug(
272+
`[${requestId}] Loaded ${Object.keys(workflowVariables).length} workflow variables for: ${workflowId}`
273+
)
285274
} else {
286275
logger.debug(`[${requestId}] No workflow variables found for: ${workflowId}`)
287276
}

apps/sim/executor/handlers/workflow/workflow-handler.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export class WorkflowBlockHandler implements BlockHandler {
8989
workflow: childWorkflow.serializedState,
9090
workflowInput: childWorkflowInput,
9191
envVarValues: context.environmentVariables,
92+
workflowVariables: childWorkflow.variables || {},
9293
})
9394

9495
const startTime = performance.now()
@@ -176,9 +177,20 @@ export class WorkflowBlockHandler implements BlockHandler {
176177
workflowState.parallels || {}
177178
)
178179

180+
const workflowVariables = (workflowData.variables as Record<string, any>) || {}
181+
182+
if (Object.keys(workflowVariables).length > 0) {
183+
logger.info(
184+
`Loaded ${Object.keys(workflowVariables).length} variables for child workflow: ${workflowId}`
185+
)
186+
} else {
187+
logger.debug(`No workflow variables found for child workflow: ${workflowId}`)
188+
}
189+
179190
return {
180191
name: workflowData.name,
181192
serializedState: serializedWorkflow,
193+
variables: workflowVariables,
182194
}
183195
} catch (error) {
184196
logger.error(`Error loading child workflow ${workflowId}:`, error)

0 commit comments

Comments
 (0)