From 5965e25ccf652f9c577ce6a1596840d8db75a7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Tue, 29 Nov 2022 15:34:03 +0100 Subject: [PATCH] :bug: Fix partial execution with pinned data on child node run --- .../cli/src/workflows/workflows.services.ts | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/workflows/workflows.services.ts b/packages/cli/src/workflows/workflows.services.ts index 5bef362de3e63..c387fa4a9cf38 100644 --- a/packages/cli/src/workflows/workflows.services.ts +++ b/packages/cli/src/workflows/workflows.services.ts @@ -70,6 +70,11 @@ export class WorkflowsService { /** * Find the pinned trigger to execute the workflow from, if any. + * + * - In a full execution, select the _first_ pinned trigger. + * - In a partial execution, + * - select the _first_ pinned trigger that leads to the executed node, + * - else select the executed pinned trigger. */ static findPinnedTrigger(workflow: IWorkflowDb, startNodes?: string[], pinData?: IPinData) { if (!pinData || !startNodes) return null; @@ -87,7 +92,22 @@ export class WorkflowsService { const [startNodeName] = startNodes; - return pinnedTriggers.find((pt) => pt.name === startNodeName) ?? null; // partial execution + const parentNames = new Workflow({ + nodes: workflow.nodes, + connections: workflow.connections, + active: workflow.active, + nodeTypes: NodeTypes(), + }).getParentNodes(startNodeName); + + let checkNodeName = ''; + + if (parentNames.length === 0) { + checkNodeName = startNodeName; + } else { + checkNodeName = parentNames.find((pn) => pn === pinnedTriggers[0].name) as string; + } + + return pinnedTriggers.find((pt) => pt.name === checkNodeName) ?? null; // partial execution } static async get(workflow: Partial, options?: { relations: string[] }) {