mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(core): Allow index as top-level item key for Code node (#12469)
This commit is contained in:
@@ -28,6 +28,7 @@ describe('result validation', () => {
|
|||||||
['binary', {}],
|
['binary', {}],
|
||||||
['pairedItem', {}],
|
['pairedItem', {}],
|
||||||
['error', {}],
|
['error', {}],
|
||||||
|
['index', {}], // temporarily allowed until refactored out
|
||||||
])(
|
])(
|
||||||
'should not throw an error if the output item has %s key in addition to json',
|
'should not throw an error if the output item has %s key in addition to json',
|
||||||
(key, value) => {
|
(key, value) => {
|
||||||
|
|||||||
@@ -4,7 +4,19 @@ import type { INodeExecutionData } from 'n8n-workflow';
|
|||||||
import { ValidationError } from './errors/validation-error';
|
import { ValidationError } from './errors/validation-error';
|
||||||
import { isObject } from './obj-utils';
|
import { isObject } from './obj-utils';
|
||||||
|
|
||||||
export const REQUIRED_N8N_ITEM_KEYS = new Set(['json', 'binary', 'pairedItem', 'error']);
|
export const REQUIRED_N8N_ITEM_KEYS = new Set([
|
||||||
|
'json',
|
||||||
|
'binary',
|
||||||
|
'pairedItem',
|
||||||
|
'error',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `index` key was added accidentally to Function, FunctionItem, Gong,
|
||||||
|
* Execute Workflow, and ToolWorkflowV2, so we need to allow it temporarily.
|
||||||
|
* Once we stop using it in all nodes, we can stop allowing the `index` key.
|
||||||
|
*/
|
||||||
|
'index',
|
||||||
|
]);
|
||||||
|
|
||||||
function validateTopLevelKeys(item: INodeExecutionData, itemIndex: number) {
|
function validateTopLevelKeys(item: INodeExecutionData, itemIndex: number) {
|
||||||
for (const key in item) {
|
for (const key in item) {
|
||||||
|
|||||||
@@ -22,7 +22,19 @@ export interface SandboxContext extends IWorkflowDataProxyData {
|
|||||||
helpers: IExecuteFunctions['helpers'];
|
helpers: IExecuteFunctions['helpers'];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const REQUIRED_N8N_ITEM_KEYS = new Set(['json', 'binary', 'pairedItem', 'error']);
|
export const REQUIRED_N8N_ITEM_KEYS = new Set([
|
||||||
|
'json',
|
||||||
|
'binary',
|
||||||
|
'pairedItem',
|
||||||
|
'error',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `index` key was added accidentally to Function, FunctionItem, Gong,
|
||||||
|
* Execute Workflow, and ToolWorkflowV2, so we need to allow it temporarily.
|
||||||
|
* Once we stop using it in all nodes, we can stop allowing the `index` key.
|
||||||
|
*/
|
||||||
|
'index',
|
||||||
|
]);
|
||||||
|
|
||||||
export function getSandboxContext(
|
export function getSandboxContext(
|
||||||
this: IExecuteFunctions | ISupplyDataFunctions,
|
this: IExecuteFunctions | ISupplyDataFunctions,
|
||||||
|
|||||||
@@ -40,6 +40,13 @@ describe('Code Node unit test', () => {
|
|||||||
[{ json: { count: 42 } }],
|
[{ json: { count: 42 } }],
|
||||||
[{ json: { count: 42 } }],
|
[{ json: { count: 42 } }],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// temporarily allowed until refactored out
|
||||||
|
'should handle an index key': [
|
||||||
|
[{ json: { count: 42 }, index: 0 }],
|
||||||
|
[{ json: { count: 42 }, index: 0 }],
|
||||||
|
],
|
||||||
|
|
||||||
'should handle when returned data is not an array': [
|
'should handle when returned data is not an array': [
|
||||||
{ json: { count: 42 } },
|
{ json: { count: 42 } },
|
||||||
[{ json: { count: 42 } }],
|
[{ json: { count: 42 } }],
|
||||||
|
|||||||
Reference in New Issue
Block a user