Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(editor): Rerun failed nodes in manual executions #9050

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion packages/editor-ui/src/composables/useRunWorkflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down Expand Up @@ -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);
});
});
});
9 changes: 7 additions & 2 deletions packages/editor-ui/src/composables/useRunWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,14 +426,19 @@ export function useRunWorkflow(options: { router: ReturnType<typeof useRouter> }
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);
}
}
Expand Down
Loading