mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-10 07:27:57 -05:00
fix(workflow-in-workflow): variables not accessible in child workflow (#783)
* fix(workflow-in-workflow): child workflow must be able to access vars * simplify
This commit is contained in:
committed by
GitHub
parent
5ddfe1b709
commit
a84c55772d
@@ -264,24 +264,13 @@ async function executeWorkflow(workflow: any, requestId: string, input?: any): P
|
|||||||
{} as Record<string, Record<string, any>>
|
{} as Record<string, Record<string, any>>
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get workflow variables
|
// Get workflow variables - they are stored as JSON objects in the database
|
||||||
let workflowVariables = {}
|
const workflowVariables = (workflow.variables as Record<string, any>) || {}
|
||||||
if (workflow.variables) {
|
|
||||||
try {
|
if (Object.keys(workflowVariables).length > 0) {
|
||||||
// Parse workflow variables if they're stored as a string
|
logger.debug(
|
||||||
if (typeof workflow.variables === 'string') {
|
`[${requestId}] Loaded ${Object.keys(workflowVariables).length} workflow variables for: ${workflowId}`
|
||||||
workflowVariables = JSON.parse(workflow.variables)
|
)
|
||||||
} else {
|
|
||||||
// Otherwise use as is (already parsed JSON)
|
|
||||||
workflowVariables = workflow.variables
|
|
||||||
}
|
|
||||||
logger.debug(
|
|
||||||
`[${requestId}] Loaded ${Object.keys(workflowVariables).length} workflow variables for: ${workflowId}`
|
|
||||||
)
|
|
||||||
} catch (error) {
|
|
||||||
logger.error(`[${requestId}] Failed to parse workflow variables: ${workflowId}`, error)
|
|
||||||
// Continue execution even if variables can't be parsed
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
logger.debug(`[${requestId}] No workflow variables found for: ${workflowId}`)
|
logger.debug(`[${requestId}] No workflow variables found for: ${workflowId}`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ export class WorkflowBlockHandler implements BlockHandler {
|
|||||||
workflow: childWorkflow.serializedState,
|
workflow: childWorkflow.serializedState,
|
||||||
workflowInput: childWorkflowInput,
|
workflowInput: childWorkflowInput,
|
||||||
envVarValues: context.environmentVariables,
|
envVarValues: context.environmentVariables,
|
||||||
|
workflowVariables: childWorkflow.variables || {},
|
||||||
})
|
})
|
||||||
|
|
||||||
const startTime = performance.now()
|
const startTime = performance.now()
|
||||||
@@ -176,9 +177,20 @@ export class WorkflowBlockHandler implements BlockHandler {
|
|||||||
workflowState.parallels || {}
|
workflowState.parallels || {}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const workflowVariables = (workflowData.variables as Record<string, any>) || {}
|
||||||
|
|
||||||
|
if (Object.keys(workflowVariables).length > 0) {
|
||||||
|
logger.info(
|
||||||
|
`Loaded ${Object.keys(workflowVariables).length} variables for child workflow: ${workflowId}`
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
logger.debug(`No workflow variables found for child workflow: ${workflowId}`)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: workflowData.name,
|
name: workflowData.name,
|
||||||
serializedState: serializedWorkflow,
|
serializedState: serializedWorkflow,
|
||||||
|
variables: workflowVariables,
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error loading child workflow ${workflowId}:`, error)
|
logger.error(`Error loading child workflow ${workflowId}:`, error)
|
||||||
|
|||||||
Reference in New Issue
Block a user