diff --git a/packages/nodes-base/nodes/Set/Set.node.ts b/packages/nodes-base/nodes/Set/Set.node.ts index 17b2404ffb9a8..e4d9af0ddf5da 100644 --- a/packages/nodes-base/nodes/Set/Set.node.ts +++ b/packages/nodes-base/nodes/Set/Set.node.ts @@ -12,7 +12,7 @@ export class Set extends VersionedNodeType { icon: 'fa:pen', group: ['input'], description: 'Add or edit fields on an input item and optionally remove other fields', - defaultVersion: 3.1, + defaultVersion: 3.2, }; const nodeVersions: IVersionedNodeType['nodeVersions'] = { @@ -20,6 +20,7 @@ export class Set extends VersionedNodeType { 2: new SetV1(baseDescription), 3: new SetV2(baseDescription), 3.1: new SetV2(baseDescription), + 3.2: new SetV2(baseDescription), }; super(nodeVersions, baseDescription); diff --git a/packages/nodes-base/nodes/Set/test/Set.workflow.null_values.json b/packages/nodes-base/nodes/Set/test/Set.workflow.null_values.json new file mode 100644 index 0000000000000..a95f04f0a7ee9 --- /dev/null +++ b/packages/nodes-base/nodes/Set/test/Set.workflow.null_values.json @@ -0,0 +1,244 @@ +{ + "name": "My workflow 31", + "nodes": [ + { + "parameters": {}, + "id": "9fe8b524-b618-4abb-821f-227ae5cc1f12", + "name": "When clicking \"Execute Workflow\"", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [ + 560, + 640 + ] + }, + { + "parameters": { + "fields": { + "values": [ + { + "name": "test1", + "stringValue": "={{ null }}" + }, + { + "name": "test2", + "stringValue": "={{ undefined }}" + } + ] + }, + "options": { + "ignoreConversionErrors": true + } + }, + "id": "78f2ad0d-e129-448b-ae78-5bfdba587186", + "name": "Edit Fields", + "type": "n8n-nodes-base.set", + "typeVersion": 3.2, + "position": [ + 1000, + 240 + ] + }, + { + "parameters": { + "fields": { + "values": [ + { + "name": "test1", + "type": "numberValue", + "numberValue": "={{ null }}" + }, + { + "name": "test2", + "type": "numberValue", + "numberValue": "={{ undefined }}" + } + ] + }, + "options": { + "ignoreConversionErrors": true + } + }, + "id": "ceaad5a1-b78c-4d38-b80d-f608f8c95f71", + "name": "Edit Fields1", + "type": "n8n-nodes-base.set", + "typeVersion": 3.2, + "position": [ + 1000, + 440 + ] + }, + { + "parameters": { + "fields": { + "values": [ + { + "name": "test1", + "type": "booleanValue", + "booleanValue": "={{ null }}" + }, + { + "name": "test2", + "type": "booleanValue", + "booleanValue": "={{ undefined }}" + } + ] + }, + "options": { + "ignoreConversionErrors": true + } + }, + "id": "0048be99-0bce-4073-86e6-2622169fe9ab", + "name": "Edit Fields2", + "type": "n8n-nodes-base.set", + "typeVersion": 3.2, + "position": [ + 1000, + 640 + ] + }, + { + "parameters": { + "fields": { + "values": [ + { + "name": "test1", + "type": "arrayValue", + "arrayValue": "={{ null }}" + }, + { + "name": "test2", + "type": "arrayValue", + "arrayValue": "={{ undefined }}" + } + ] + }, + "options": { + "ignoreConversionErrors": true + } + }, + "id": "aa254a34-9267-42a2-9730-c2ab64760721", + "name": "Edit Fields3", + "type": "n8n-nodes-base.set", + "typeVersion": 3.2, + "position": [ + 1000, + 840 + ] + }, + { + "parameters": { + "fields": { + "values": [ + { + "name": "test1", + "type": "objectValue", + "objectValue": "={{ null }}" + }, + { + "name": "test2", + "type": "objectValue", + "objectValue": "={{ undefined }}" + } + ] + }, + "options": { + "ignoreConversionErrors": true + } + }, + "id": "03e4acf2-ceaf-4a27-adb7-d074a95e9cc9", + "name": "Edit Fields4", + "type": "n8n-nodes-base.set", + "typeVersion": 3.2, + "position": [ + 1000, + 1020 + ] + } + ], + "pinData": { + "Edit Fields": [ + { + "json": { + "test1": null, + "test2": null + } + } + ], + "Edit Fields1": [ + { + "json": { + "test1": null, + "test2": null + } + } + ], + "Edit Fields2": [ + { + "json": { + "test1": null, + "test2": null + } + } + ], + "Edit Fields3": [ + { + "json": { + "test1": null, + "test2": null + } + } + ], + "Edit Fields4": [ + { + "json": { + "test1": null, + "test2": null + } + } + ] + }, + "connections": { + "When clicking \"Execute Workflow\"": { + "main": [ + [ + { + "node": "Edit Fields", + "type": "main", + "index": 0 + }, + { + "node": "Edit Fields1", + "type": "main", + "index": 0 + }, + { + "node": "Edit Fields2", + "type": "main", + "index": 0 + }, + { + "node": "Edit Fields3", + "type": "main", + "index": 0 + }, + { + "node": "Edit Fields4", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + }, + "versionId": "016f70db-c529-43e9-a077-2e0d81859747", + "id": "ZfMuVQ1861mlPIKe", + "meta": { + "instanceId": "b888bd11cd1ddbb95450babf3e199556799d999b896f650de768b8370ee50363" + }, + "tags": [] +} diff --git a/packages/nodes-base/nodes/Set/v2/SetV2.node.ts b/packages/nodes-base/nodes/Set/v2/SetV2.node.ts index 5a9f92ef776d5..62a860140166d 100644 --- a/packages/nodes-base/nodes/Set/v2/SetV2.node.ts +++ b/packages/nodes-base/nodes/Set/v2/SetV2.node.ts @@ -21,7 +21,7 @@ const versionDescription: INodeTypeDescription = { name: 'set', icon: 'fa:pen', group: ['input'], - version: [3, 3.1], + version: [3, 3.1, 3.2], description: 'Change the structure of your items', subtitle: '={{$parameter["mode"]}}', defaults: { diff --git a/packages/nodes-base/nodes/Set/v2/helpers/utils.ts b/packages/nodes-base/nodes/Set/v2/helpers/utils.ts index fc947e23a4494..9a27ba44c07d3 100644 --- a/packages/nodes-base/nodes/Set/v2/helpers/utils.ts +++ b/packages/nodes-base/nodes/Set/v2/helpers/utils.ts @@ -163,6 +163,11 @@ export const validateEntry = ( ) => { let entryValue = entry[entry.type]; const name = entry.name; + + if (nodeVersion && nodeVersion >= 3.2 && (entryValue === undefined || entryValue === null)) { + return { name, value: null }; + } + const entryType = entry.type.replace('Value', '') as FieldType; const description = `To fix the error try to change the type for the field "${name}" or activate the option “Ignore Type Conversion Errors” to apply a less strict type validation`; diff --git a/packages/nodes-base/nodes/Set/v2/manual.mode.ts b/packages/nodes-base/nodes/Set/v2/manual.mode.ts index 8ab10be69a101..c1411d1463e83 100644 --- a/packages/nodes-base/nodes/Set/v2/manual.mode.ts +++ b/packages/nodes-base/nodes/Set/v2/manual.mode.ts @@ -182,7 +182,12 @@ export async function execute( const newData: IDataObject = {}; for (const entry of fields) { - if (entry.type === 'objectValue' && rawFieldsData[entry.name] !== undefined) { + if ( + entry.type === 'objectValue' && + rawFieldsData[entry.name] !== undefined && + entry.objectValue !== undefined && + entry.objectValue !== null + ) { entry.objectValue = parseJsonParameter( resolveRawData.call(this, rawFieldsData[entry.name] as string, i), node,