Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Set Node): Null should not throw an error #7416

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/nodes-base/nodes/Set/Set.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ 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'] = {
1: new SetV1(baseDescription),
2: new SetV1(baseDescription),
3: new SetV2(baseDescription),
3.1: new SetV2(baseDescription),
3.2: new SetV2(baseDescription),
};

super(nodeVersions, baseDescription);
Expand Down
244 changes: 244 additions & 0 deletions packages/nodes-base/nodes/Set/test/Set.workflow.null_values.json
Original file line number Diff line number Diff line change
@@ -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": []
}
2 changes: 1 addition & 1 deletion packages/nodes-base/nodes/Set/v2/SetV2.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
5 changes: 5 additions & 0 deletions packages/nodes-base/nodes/Set/v2/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
7 changes: 6 additions & 1 deletion packages/nodes-base/nodes/Set/v2/manual.mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading