From b47f4bc012b9379b3ea21725101c03daf222b87c Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sat, 8 May 2021 21:49:55 -0500 Subject: [PATCH] :bug: Fix issue that nodes did execute even if there was no input data --- packages/core/src/WorkflowExecute.ts | 7 + packages/core/test/Helpers.ts | 24 +++ packages/core/test/WorkflowExecute.test.ts | 170 ++++++++++++++++++++- 3 files changed, 199 insertions(+), 2 deletions(-) diff --git a/packages/core/src/WorkflowExecute.ts b/packages/core/src/WorkflowExecute.ts index 8d474a458f..5c73d4c9ef 100644 --- a/packages/core/src/WorkflowExecute.ts +++ b/packages/core/src/WorkflowExecute.ts @@ -401,6 +401,13 @@ export class WorkflowExecute { nodeToAdd = parentNode; } + const parentNodesNodeToAdd = workflow.getParentNodes(nodeToAdd as string); + if (parentNodesNodeToAdd.includes(parentNodeName) && nodeSuccessData[outputIndex].length === 0) { + // We do not add the node if there is no input data and the node that should be connected + // is a child of the parent node. Because else it would run a node even though it should be + // specifically not run, as it did not receive any data. + nodeToAdd = undefined; + } if (nodeToAdd === undefined) { // No node has to get added so process diff --git a/packages/core/test/Helpers.ts b/packages/core/test/Helpers.ts index 4335e9e1e9..1a1fa9d12d 100644 --- a/packages/core/test/Helpers.ts +++ b/packages/core/test/Helpers.ts @@ -465,6 +465,30 @@ class NodeTypesClass implements INodeTypes { }, }, }, + 'n8n-nodes-base.noOp': { + sourcePath: '', + type: { + description: { + displayName: 'No Operation, do nothing', + name: 'noOp', + icon: 'fa:arrow-right', + group: ['organization'], + version: 1, + description: 'No Operation', + defaults: { + name: 'NoOp', + color: '#b0b0b0', + }, + inputs: ['main'], + outputs: ['main'], + properties: [], + }, + execute(this: IExecuteFunctions): Promise { + const items = this.getInputData(); + return this.prepareOutputData(items); + }, + }, + }, 'n8n-nodes-base.set': { sourcePath: '', type: { diff --git a/packages/core/test/WorkflowExecute.test.ts b/packages/core/test/WorkflowExecute.test.ts index 8c7a51c0ba..454dd521b5 100644 --- a/packages/core/test/WorkflowExecute.test.ts +++ b/packages/core/test/WorkflowExecute.test.ts @@ -1154,6 +1154,174 @@ describe('WorkflowExecute', () => { }, }, }, + { + description: 'should not use empty data in sibling if parent did not send any data', + input: { + // Leave the workflowData in regular JSON to be able to easily + // copy it from/in the UI + workflowData: { + "nodes": [ + { + "parameters": {}, + "name": "Start", + "type": "n8n-nodes-base.start", + "typeVersion": 1, + "position": [ + 250, + 300, + ], + }, + { + "parameters": { + "values": { + "number": [ + { + "name": "value1", + }, + ], + }, + "options": {}, + }, + "name": "Set", + "type": "n8n-nodes-base.set", + "typeVersion": 1, + "position": [ + 450, + 300, + ], + }, + { + "parameters": {}, + "name": "Merge", + "type": "n8n-nodes-base.merge", + "typeVersion": 1, + "position": [ + 1050, + 250, + ], + }, + { + "parameters": { + "conditions": { + "number": [ + { + "value1": "={{$json[\"value1\"]}}", + "operation": "equal", + "value2": 1, + }, + ], + }, + }, + "name": "IF", + "type": "n8n-nodes-base.if", + "typeVersion": 1, + "position": [ + 650, + 300, + ], + }, + { + "parameters": {}, + "name": "NoOpTrue", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [ + 850, + 150, + ], + }, + { + "parameters": {}, + "name": "NoOpFalse", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [ + 850, + 400, + ], + }, + ], + "connections": { + "Start": { + "main": [ + [ + { + "node": "Set", + "type": "main", + "index": 0, + }, + ], + ], + }, + "Set": { + "main": [ + [ + { + "node": "IF", + "type": "main", + "index": 0, + }, + ], + ], + }, + "IF": { + "main": [ + [ + { + "node": "NoOpTrue", + "type": "main", + "index": 0, + }, + { + "node": "Merge", + "type": "main", + "index": 1, + }, + ], + [ + { + "node": "NoOpFalse", + "type": "main", + "index": 0, + }, + ], + ], + }, + "NoOpTrue": { + "main": [ + [ + { + "node": "Merge", + "type": "main", + "index": 0, + }, + ], + ], + }, + }, + }, + }, + output: { + nodeExecutionOrder: [ + 'Start', + 'Set', + 'IF', + 'NoOpFalse', + ], + nodeData: { + IF: [ + [], + ], + NoOpFalse: [ + [ + { + value1: 0, + }, + ], + ], + }, + }, + }, ]; const fakeLogger = { @@ -1165,7 +1333,6 @@ describe('WorkflowExecute', () => { error: () => {}, } as ILogger; - const executionMode = 'manual'; const nodeTypes = Helpers.NodeTypes(); LoggerProxy.init(fakeLogger); @@ -1213,7 +1380,6 @@ describe('WorkflowExecute', () => { expect(result.finished).toEqual(true); expect(result.data.executionData!.contextData).toEqual({}); expect(result.data.executionData!.nodeExecutionStack).toEqual([]); - expect(result.data.executionData!.waitingExecution).toEqual({}); }); }