Skip to content

Commit

Permalink
fix(core): Remove circular references before serializing executions i…
Browse files Browse the repository at this point in the history
…n 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.
  • Loading branch information
netroy authored Dec 15, 2023
1 parent 1e7a309 commit 989888d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type express from 'express';
import { Container } from 'typedi';
import { replaceCircularReferences } from 'n8n-workflow';

import { getExecutions, getExecutionInWorkflows, getExecutionsCount } from './executions.service';
import { ActiveExecutions } from '@/ActiveExecutions';
import { authorize, validCursor } from '../../shared/middlewares/global.middleware';
import type { ExecutionRequest } from '../../../types';
import { getSharedWorkflowIds } from '../workflows/workflows.service';
import { encodeNextCursor } from '../../shared/services/pagination.service';
import { Container } from 'typedi';
import { InternalHooks } from '@/InternalHooks';
import { ExecutionRepository } from '@db/repositories/execution.repository';

Expand Down Expand Up @@ -38,7 +39,7 @@ export = {

execution.id = id;

return res.json(execution);
return res.json(replaceCircularReferences(execution));
},
],
getExecution: [
Expand Down Expand Up @@ -67,7 +68,7 @@ export = {
public_api: true,
});

return res.json(execution);
return res.json(replaceCircularReferences(execution));
},
],
getExecutions: [
Expand Down Expand Up @@ -118,7 +119,7 @@ export = {
});

return res.json({
data: executions,
data: replaceCircularReferences(executions),
nextCursor: encodeNextCursor({
lastId: newLastId,
limit,
Expand Down
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"cron": "1.7.2",
"fast-glob": "3.2.12",
"file-type": "16.5.4",
"flatted": "3.2.7",
"form-data": "4.0.0",
"lodash": "4.17.21",
"mime-types": "2.1.35",
Expand Down
1 change: 1 addition & 0 deletions packages/workflow/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export {
deepCopy,
jsonParse,
jsonStringify,
replaceCircularReferences,
sleep,
fileTypeFromMimeType,
assert,
Expand Down
2 changes: 1 addition & 1 deletion packages/workflow/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type JSONStringifyOptions = {
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 ('toJSON' in value && typeof value.toJSON === 'function') return value.toJSON() as T;
if (knownObjects.has(value)) return '[Circular Reference]' as T;
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 989888d

Please sign in to comment.