mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(Merge Node): Do not error if expected key is missing
This commit is contained in:
@@ -5,7 +5,12 @@ import type {
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import { checkInput, checkMatchFieldsInput, findMatches } from './GenericFunctions';
|
||||
import {
|
||||
checkInput,
|
||||
checkInputAndThrowError,
|
||||
checkMatchFieldsInput,
|
||||
findMatches,
|
||||
} from './GenericFunctions';
|
||||
|
||||
export class CompareDatasets implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -13,7 +18,7 @@ export class CompareDatasets implements INodeType {
|
||||
name: 'compareDatasets',
|
||||
icon: 'file:compare.svg',
|
||||
group: ['transform'],
|
||||
version: [1, 2, 2.1],
|
||||
version: [1, 2, 2.1, 2.2],
|
||||
description: 'Compare two inputs for changes',
|
||||
defaults: { name: 'Compare Datasets' },
|
||||
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node
|
||||
@@ -254,19 +259,26 @@ export class CompareDatasets implements INodeType {
|
||||
options.fuzzyCompare = this.getNodeParameter('fuzzyCompare', 0, false) as boolean;
|
||||
}
|
||||
|
||||
const input1 = checkInput(
|
||||
this.getInputData(0),
|
||||
matchFields.map((pair) => pair.field1),
|
||||
(options.disableDotNotation as boolean) || false,
|
||||
'Input A',
|
||||
);
|
||||
let input1 = this.getInputData(0);
|
||||
let input2 = this.getInputData(1);
|
||||
if (options.nodeVersion < 2.2) {
|
||||
input1 = checkInputAndThrowError(
|
||||
input1,
|
||||
matchFields.map((pair) => pair.field1),
|
||||
(options.disableDotNotation as boolean) || false,
|
||||
'Input A',
|
||||
);
|
||||
|
||||
const input2 = checkInput(
|
||||
this.getInputData(1),
|
||||
matchFields.map((pair) => pair.field2),
|
||||
(options.disableDotNotation as boolean) || false,
|
||||
'Input B',
|
||||
);
|
||||
input2 = checkInputAndThrowError(
|
||||
input2,
|
||||
matchFields.map((pair) => pair.field2),
|
||||
(options.disableDotNotation as boolean) || false,
|
||||
'Input B',
|
||||
);
|
||||
} else {
|
||||
input1 = checkInput(input1);
|
||||
input2 = checkInput(input2);
|
||||
}
|
||||
|
||||
const resolve = this.getNodeParameter('resolve', 0, '') as string;
|
||||
options.resolve = resolve;
|
||||
|
||||
@@ -414,7 +414,15 @@ export function checkMatchFieldsInput(data: IDataObject[]) {
|
||||
return data as PairToMatch[];
|
||||
}
|
||||
|
||||
export function checkInput(
|
||||
export function checkInput(input: INodeExecutionData[]) {
|
||||
if (!input) return [];
|
||||
if (input.some((item) => isEmpty(item.json))) {
|
||||
input = input.filter((item) => !isEmpty(item.json));
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
export function checkInputAndThrowError(
|
||||
input: INodeExecutionData[],
|
||||
fields: string[],
|
||||
disableDotNotation: boolean,
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
{
|
||||
"name": "do not error on missing keys",
|
||||
"nodes": [
|
||||
{
|
||||
"parameters": {},
|
||||
"id": "c7c0cf66-790a-4da7-81c8-ba9e4bbcec9a",
|
||||
"name": "When clicking \"Execute Workflow\"",
|
||||
"type": "n8n-nodes-base.manualTrigger",
|
||||
"typeVersion": 1,
|
||||
"position": [720, 300]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"jsCode": "return [\n {id: 1},\n {id: 2},\n {id: 3},\n {id: 4},\n];"
|
||||
},
|
||||
"id": "cec18624-ced0-4de1-8987-d4b184b136b9",
|
||||
"name": "Code",
|
||||
"type": "n8n-nodes-base.code",
|
||||
"typeVersion": 1,
|
||||
"position": [1020, 200]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"jsCode": "return [\n];"
|
||||
},
|
||||
"id": "754d549c-82ce-4625-ba2b-6f8edcbf715e",
|
||||
"name": "Code1",
|
||||
"type": "n8n-nodes-base.code",
|
||||
"typeVersion": 1,
|
||||
"position": [1020, 400]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"mergeByFields": {
|
||||
"values": [
|
||||
{
|
||||
"field1": "idd",
|
||||
"field2": "idd"
|
||||
}
|
||||
]
|
||||
},
|
||||
"options": {}
|
||||
},
|
||||
"id": "1b3660a2-a490-4524-a8ac-cd42fa2b340b",
|
||||
"name": "Compare Datasets",
|
||||
"type": "n8n-nodes-base.compareDatasets",
|
||||
"typeVersion": 2.2,
|
||||
"position": [1300, 420]
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"mergeByFields": {
|
||||
"values": [
|
||||
{
|
||||
"field1": "idd",
|
||||
"field2": "idd"
|
||||
}
|
||||
]
|
||||
},
|
||||
"options": {}
|
||||
},
|
||||
"id": "17e9b83b-828c-41a0-a7ba-e33cc66d37ad",
|
||||
"name": "Any skipped",
|
||||
"type": "n8n-nodes-base.compareDatasets",
|
||||
"typeVersion": 2.1,
|
||||
"position": [1300, 180],
|
||||
"continueOnFail": true
|
||||
},
|
||||
{
|
||||
"parameters": {},
|
||||
"id": "551ed574-607a-4d98-9b06-350df92c805e",
|
||||
"name": "No Operation, do nothing",
|
||||
"type": "n8n-nodes-base.noOp",
|
||||
"typeVersion": 1,
|
||||
"position": [1540, 200]
|
||||
},
|
||||
{
|
||||
"parameters": {},
|
||||
"id": "00e75760-d88e-413c-b276-c759db72411f",
|
||||
"name": "No Operation, do nothing1",
|
||||
"type": "n8n-nodes-base.noOp",
|
||||
"typeVersion": 1,
|
||||
"position": [1540, 360]
|
||||
}
|
||||
],
|
||||
"pinData": {
|
||||
"No Operation, do nothing": [
|
||||
{
|
||||
"json": {
|
||||
"id": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"json": {
|
||||
"id": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"json": {
|
||||
"id": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"json": {
|
||||
"id": 4
|
||||
}
|
||||
}
|
||||
],
|
||||
"No Operation, do nothing1": [
|
||||
{
|
||||
"json": {
|
||||
"id": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"json": {
|
||||
"id": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"json": {
|
||||
"id": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"json": {
|
||||
"id": 4
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"connections": {
|
||||
"When clicking \"Execute Workflow\"": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Code",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"node": "Code1",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Code": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Compare Datasets",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
},
|
||||
{
|
||||
"node": "Any skipped",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Code1": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Compare Datasets",
|
||||
"type": "main",
|
||||
"index": 1
|
||||
},
|
||||
{
|
||||
"node": "Any skipped",
|
||||
"type": "main",
|
||||
"index": 1
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Any skipped": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "No Operation, do nothing",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Compare Datasets": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "No Operation, do nothing1",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
"active": false,
|
||||
"settings": {},
|
||||
"versionId": "11347bae-96af-4b28-80d7-fe272a165790",
|
||||
"id": "8",
|
||||
"meta": {
|
||||
"instanceId": "6ebec4953fe56f1c009e7c3b107578b375137523af057073c0b5da17350651bd"
|
||||
},
|
||||
"tags": []
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import type { INodeExecutionData } from 'n8n-workflow';
|
||||
import { checkInput } from '../../GenericFunctions';
|
||||
|
||||
describe('Test Compare Datasets Node utils', () => {
|
||||
it('test checkInput', () => {
|
||||
const input1 = [
|
||||
{ json: {} },
|
||||
{
|
||||
json: {
|
||||
name: 'Test',
|
||||
age: 30,
|
||||
},
|
||||
},
|
||||
{
|
||||
json: {
|
||||
name: 'Test2',
|
||||
age: 30,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
expect(checkInput(input1).length).toEqual(2);
|
||||
|
||||
const input2: INodeExecutionData[] = [{ json: {} }];
|
||||
|
||||
expect(checkInput(input2).length).toEqual(0);
|
||||
|
||||
const input3 = undefined;
|
||||
|
||||
expect(checkInput(input3 as unknown as INodeExecutionData[]).length).toEqual(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user