fix(Remove Duplicates Node): Tolerate null fields (#9642)

This commit is contained in:
Michael Kret
2024-06-06 16:52:56 +03:00
committed by GitHub
parent ed963011c9
commit a684681ea1
3 changed files with 105 additions and 34 deletions

View File

@@ -10,7 +10,7 @@ import {
type INodeTypeDescription,
} from 'n8n-workflow';
import { prepareFieldsArray } from '../utils/utils';
import { compareItems, flattenKeys } from './utils';
import { compareItems, flattenKeys, validateInputData } from './utils';
export class RemoveDuplicates implements INodeType {
description: INodeTypeDescription = {
@@ -19,7 +19,7 @@ export class RemoveDuplicates implements INodeType {
icon: 'file:removeDuplicates.svg',
group: ['transform'],
subtitle: '',
version: 1,
version: [1, 1.1],
description: 'Delete items with matching field values',
defaults: {
name: 'Remove Duplicates',
@@ -205,37 +205,7 @@ export class RemoveDuplicates implements INodeType {
return result;
});
for (const key of keys) {
let type: any = undefined;
for (const item of newItems) {
if (key === '') {
throw new NodeOperationError(this.getNode(), 'Name of field to compare is blank');
}
const value = !disableDotNotation ? get(item.json, key) : item.json[key];
if (value === undefined && disableDotNotation && key.includes('.')) {
throw new NodeOperationError(
this.getNode(),
`'${key}' field is missing from some input items`,
{
description:
"If you're trying to use a nested field, make sure you turn off 'disable dot notation' in the node options",
},
);
} else if (value === undefined) {
throw new NodeOperationError(
this.getNode(),
`'${key}' field is missing from some input items`,
);
}
if (type !== undefined && value !== undefined && type !== typeof value) {
throw new NodeOperationError(this.getNode(), `'${key}' isn't always the same type`, {
description: 'The type of this field varies between items',
});
} else {
type = typeof value;
}
}
}
validateInputData(this.getNode(), newItems, keys, disableDotNotation);
// collect the original indexes of items to be removed
const removedIndexes: number[] = [];