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): Do not stringify null and undefined #7313

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,13 +12,14 @@ 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,
defaultVersion: 3.1,
};

const nodeVersions: IVersionedNodeType['nodeVersions'] = {
1: new SetV1(baseDescription),
2: new SetV1(baseDescription),
3: new SetV2(baseDescription),
3.1: new SetV2(baseDescription),
};

super(nodeVersions, baseDescription);
Expand Down
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,
version: [3, 3.1],
description: 'Change the structure of your items',
subtitle: '={{$parameter["mode"]}}',
defaults: {
Expand Down
16 changes: 14 additions & 2 deletions packages/nodes-base/nodes/Set/v2/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,26 @@ export const validateEntry = (
node: INode,
itemIndex: number,
ignoreErrors = false,
nodeVersion?: number,
) => {
let entryValue = entry[entry.type];
const name = entry.name;
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`;

if (entryType === 'string') {
if (typeof entryValue === 'object') {
if (nodeVersion && nodeVersion > 3 && (entryValue === undefined || entryValue === null)) {
if (ignoreErrors) {
return { name, value: null };
elsmr marked this conversation as resolved.
Show resolved Hide resolved
} else {
throw new NodeOperationError(
node,
`'${name}' expects a ${entryType} but we got '${String(entryValue)}' [item ${itemIndex}]`,
{ description },
);
}
} else if (typeof entryValue === 'object') {
entryValue = JSON.stringify(entryValue);
} else {
entryValue = String(entryValue);
Expand All @@ -179,7 +192,6 @@ export const validateEntry = (
validationResult.newValue = entry[entry.type];
} else {
const message = `${validationResult.errorMessage} [item ${itemIndex}]`;
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`;
throw new NodeOperationError(node, message, {
itemIndex,
description,
Expand Down
8 changes: 7 additions & 1 deletion packages/nodes-base/nodes/Set/v2/manual.mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,13 @@ export async function execute(
);
}

const { name, value } = validateEntry(entry, node, i, options.ignoreConversionErrors);
const { name, value } = validateEntry(
entry,
node,
i,
options.ignoreConversionErrors,
node.typeVersion,
);
newData[name] = value;
}

Expand Down
Loading