From a30e02dd3844adac4b10faaa3c4a4f94e1ba1097 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Thu, 4 Apr 2024 10:28:35 +0100 Subject: [PATCH] fix(editor): Rerun failed nodes in manual executions (#9050) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Iván Ovejero --- .../src/composables/useRunWorkflow.test.ts | 31 ++++++++++++++++++- .../src/composables/useRunWorkflow.ts | 9 ++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/packages/editor-ui/src/composables/useRunWorkflow.test.ts b/packages/editor-ui/src/composables/useRunWorkflow.test.ts index 2908e50820dbd..043747dae480c 100644 --- a/packages/editor-ui/src/composables/useRunWorkflow.test.ts +++ b/packages/editor-ui/src/composables/useRunWorkflow.test.ts @@ -9,7 +9,7 @@ import { useToast } from '@/composables/useToast'; import { useWorkflowHelpers } from '@/composables/useWorkflowHelpers'; import { useNodeHelpers } from '@/composables/useNodeHelpers'; import { useRouter } from 'vue-router'; -import type { IPinData, IRunData, Workflow } from 'n8n-workflow'; +import { ExpressionError, type IPinData, type IRunData, type Workflow } from 'n8n-workflow'; vi.mock('@/stores/n8nRoot.store', () => ({ useRootStore: vi.fn().mockReturnValue({ pushConnectionActive: true }), @@ -285,5 +285,34 @@ describe('useRunWorkflow({ router })', () => { expect(result.startNodeNames).toContain('node1'); expect(result.runData).toBeUndefined(); }); + + it('should rerun failed parent nodes, adding them to the returned list of start nodes and not adding their result to runData', () => { + const { consolidateRunDataAndStartNodes } = useRunWorkflow({ router }); + const directParentNodes = ['node1']; + const runData = { + node1: [ + { + error: new ExpressionError('error'), + }, + ], + } as unknown as IRunData; + const workflowMock = { + getParentNodes: vi.fn().mockReturnValue([]), + nodes: { + node1: { disabled: false }, + node2: { disabled: false }, + }, + } as unknown as Workflow; + + const result = consolidateRunDataAndStartNodes( + directParentNodes, + runData, + undefined, + workflowMock, + ); + + expect(result.startNodeNames).toContain('node1'); + expect(result.runData).toEqual(undefined); + }); }); }); diff --git a/packages/editor-ui/src/composables/useRunWorkflow.ts b/packages/editor-ui/src/composables/useRunWorkflow.ts index 4de294d02d58d..384cdba8fb915 100644 --- a/packages/editor-ui/src/composables/useRunWorkflow.ts +++ b/packages/editor-ui/src/composables/useRunWorkflow.ts @@ -428,14 +428,19 @@ export function useRunWorkflow(options: { router: ReturnType } parentNodes.push(directParentNode); for (const parentNode of parentNodes) { - if (!runData[parentNode]?.length && !pinData?.[parentNode]?.length) { + // We want to execute nodes that don't have run data neither pin data + // in addition, if a node failed we want to execute it again + if ( + (!runData[parentNode]?.length && !pinData?.[parentNode]?.length) || + runData[parentNode]?.[0]?.error !== undefined + ) { // When we hit a node which has no data we stop and set it // as a start node the execution from and then go on with other // direct input nodes startNodeNames.push(parentNode); break; } - if (runData[parentNode]) { + if (runData[parentNode] && !runData[parentNode]?.[0]?.error) { newRunData[parentNode] = runData[parentNode]?.slice(0, 1); } }