fix(core): Account for readonly properties when replacing circular references (#18408)

This commit is contained in:
Iván Ovejero
2025-08-15 14:32:21 +02:00
committed by GitHub
parent 18137e1290
commit 3848673921

View File

@@ -1,12 +1,13 @@
import { ApplicationError } from '@n8n/errors';
import { parse as esprimaParse, Syntax } from 'esprima-next';
import type { Node as SyntaxNode, ExpressionStatement } from 'esprima-next';
import FormData from 'form-data';
import merge from 'lodash/merge';
import { ALPHABET } from './constants';
import { ApplicationError } from '@n8n/errors';
import { ExecutionCancelledError } from './errors/execution-cancelled.error';
import type { BinaryFileType, IDisplayOptions, INodeProperties, JsonObject } from './interfaces';
import * as LoggerProxy from './logger-proxy';
const readStreamClasses = new Set(['ReadStream', 'Readable', 'ReadableStream']);
@@ -181,7 +182,18 @@ export const replaceCircularReferences = <T>(value: T, knownObjects = new WeakSe
knownObjects.add(value);
const copy = (Array.isArray(value) ? [] : {}) as T;
for (const key in value) {
copy[key] = replaceCircularReferences(value[key], knownObjects);
try {
copy[key] = replaceCircularReferences(value[key], knownObjects);
} catch (error: unknown) {
if (
error instanceof TypeError &&
error.message.includes('Cannot assign to read only property')
) {
LoggerProxy.error('Error while replacing circular references: ' + error.message, { error });
continue; // Skip properties that cannot be assigned to (readonly, non-configurable, etc.)
}
throw error;
}
}
knownObjects.delete(value);
return copy;