🐛 Fix issue that nodes did execute even if there was no input data

This commit is contained in:
Jan Oberhauser 2021-05-08 21:49:55 -05:00
parent 29b9ebfaff
commit b47f4bc012
3 changed files with 199 additions and 2 deletions

View file

@ -401,6 +401,13 @@ export class WorkflowExecute {
nodeToAdd = parentNode; 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) { if (nodeToAdd === undefined) {
// No node has to get added so process // No node has to get added so process

View file

@ -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<INodeExecutionData[][]> {
const items = this.getInputData();
return this.prepareOutputData(items);
},
},
},
'n8n-nodes-base.set': { 'n8n-nodes-base.set': {
sourcePath: '', sourcePath: '',
type: { type: {

View file

@ -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 = { const fakeLogger = {
@ -1165,7 +1333,6 @@ describe('WorkflowExecute', () => {
error: () => {}, error: () => {},
} as ILogger; } as ILogger;
const executionMode = 'manual'; const executionMode = 'manual';
const nodeTypes = Helpers.NodeTypes(); const nodeTypes = Helpers.NodeTypes();
LoggerProxy.init(fakeLogger); LoggerProxy.init(fakeLogger);
@ -1213,7 +1380,6 @@ describe('WorkflowExecute', () => {
expect(result.finished).toEqual(true); expect(result.finished).toEqual(true);
expect(result.data.executionData!.contextData).toEqual({}); expect(result.data.executionData!.contextData).toEqual({});
expect(result.data.executionData!.nodeExecutionStack).toEqual([]); expect(result.data.executionData!.nodeExecutionStack).toEqual([]);
expect(result.data.executionData!.waitingExecution).toEqual({});
}); });
} }