mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
fix(Set Node): Null should not throw an error (#7416)
Github issue / Community forum post (link here to close automatically):
This commit is contained in:
parent
46977a2aff
commit
e9b6ab04cd
|
@ -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);
|
||||
|
|
244
packages/nodes-base/nodes/Set/test/Set.workflow.null_values.json
Normal file
244
packages/nodes-base/nodes/Set/test/Set.workflow.null_values.json
Normal file
|
@ -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": []
|
||||
}
|
|
@ -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: {
|
||||
|
|
|
@ -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`;
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue