mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 12:44:07 -08:00
fix(core): Remove circular references before serializing executions in public API (#8043)
## Summary Handle circular references in the public API for executions created prior to the fix from #8030 ## Related tickets [PAY-1119](https://linear.app/n8n/issue/PAY-1119) ## Review / Merge checklist - [x] PR title and summary are descriptive.
This commit is contained in:
parent
1e7a309e63
commit
989888d9bc
|
@ -1,4 +1,6 @@
|
||||||
import type express from 'express';
|
import type express from 'express';
|
||||||
|
import { Container } from 'typedi';
|
||||||
|
import { replaceCircularReferences } from 'n8n-workflow';
|
||||||
|
|
||||||
import { getExecutions, getExecutionInWorkflows, getExecutionsCount } from './executions.service';
|
import { getExecutions, getExecutionInWorkflows, getExecutionsCount } from './executions.service';
|
||||||
import { ActiveExecutions } from '@/ActiveExecutions';
|
import { ActiveExecutions } from '@/ActiveExecutions';
|
||||||
|
@ -6,7 +8,6 @@ import { authorize, validCursor } from '../../shared/middlewares/global.middlewa
|
||||||
import type { ExecutionRequest } from '../../../types';
|
import type { ExecutionRequest } from '../../../types';
|
||||||
import { getSharedWorkflowIds } from '../workflows/workflows.service';
|
import { getSharedWorkflowIds } from '../workflows/workflows.service';
|
||||||
import { encodeNextCursor } from '../../shared/services/pagination.service';
|
import { encodeNextCursor } from '../../shared/services/pagination.service';
|
||||||
import { Container } from 'typedi';
|
|
||||||
import { InternalHooks } from '@/InternalHooks';
|
import { InternalHooks } from '@/InternalHooks';
|
||||||
import { ExecutionRepository } from '@db/repositories/execution.repository';
|
import { ExecutionRepository } from '@db/repositories/execution.repository';
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ export = {
|
||||||
|
|
||||||
execution.id = id;
|
execution.id = id;
|
||||||
|
|
||||||
return res.json(execution);
|
return res.json(replaceCircularReferences(execution));
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
getExecution: [
|
getExecution: [
|
||||||
|
@ -67,7 +68,7 @@ export = {
|
||||||
public_api: true,
|
public_api: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.json(execution);
|
return res.json(replaceCircularReferences(execution));
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
getExecutions: [
|
getExecutions: [
|
||||||
|
@ -118,7 +119,7 @@ export = {
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.json({
|
return res.json({
|
||||||
data: executions,
|
data: replaceCircularReferences(executions),
|
||||||
nextCursor: encodeNextCursor({
|
nextCursor: encodeNextCursor({
|
||||||
lastId: newLastId,
|
lastId: newLastId,
|
||||||
limit,
|
limit,
|
||||||
|
|
|
@ -55,7 +55,6 @@
|
||||||
"cron": "1.7.2",
|
"cron": "1.7.2",
|
||||||
"fast-glob": "3.2.12",
|
"fast-glob": "3.2.12",
|
||||||
"file-type": "16.5.4",
|
"file-type": "16.5.4",
|
||||||
"flatted": "3.2.7",
|
|
||||||
"form-data": "4.0.0",
|
"form-data": "4.0.0",
|
||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21",
|
||||||
"mime-types": "2.1.35",
|
"mime-types": "2.1.35",
|
||||||
|
|
|
@ -28,6 +28,7 @@ export {
|
||||||
deepCopy,
|
deepCopy,
|
||||||
jsonParse,
|
jsonParse,
|
||||||
jsonStringify,
|
jsonStringify,
|
||||||
|
replaceCircularReferences,
|
||||||
sleep,
|
sleep,
|
||||||
fileTypeFromMimeType,
|
fileTypeFromMimeType,
|
||||||
assert,
|
assert,
|
||||||
|
|
|
@ -89,7 +89,7 @@ type JSONStringifyOptions = {
|
||||||
replaceCircularRefs?: boolean;
|
replaceCircularRefs?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const replaceCircularReferences = <T>(value: T, knownObjects = new WeakSet()): T => {
|
export const replaceCircularReferences = <T>(value: T, knownObjects = new WeakSet()): T => {
|
||||||
if (typeof value !== 'object' || value === null || value instanceof RegExp) return value;
|
if (typeof value !== 'object' || value === null || value instanceof RegExp) return value;
|
||||||
if ('toJSON' in value && typeof value.toJSON === 'function') return value.toJSON() as T;
|
if ('toJSON' in value && typeof value.toJSON === 'function') return value.toJSON() as T;
|
||||||
if (knownObjects.has(value)) return '[Circular Reference]' as T;
|
if (knownObjects.has(value)) return '[Circular Reference]' as T;
|
||||||
|
|
|
@ -832,9 +832,6 @@ importers:
|
||||||
file-type:
|
file-type:
|
||||||
specifier: 16.5.4
|
specifier: 16.5.4
|
||||||
version: 16.5.4
|
version: 16.5.4
|
||||||
flatted:
|
|
||||||
specifier: 3.2.7
|
|
||||||
version: 3.2.7
|
|
||||||
form-data:
|
form-data:
|
||||||
specifier: 4.0.0
|
specifier: 4.0.0
|
||||||
version: 4.0.0
|
version: 4.0.0
|
||||||
|
|
Loading…
Reference in a new issue