From b203665866b3240402322402ef935fbd38895fcd Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Thu, 12 Oct 2023 12:22:42 +0200 Subject: [PATCH 1/2] fix: Prevent undefined issues when restoring binary data --- packages/cli/src/executionLifecycleHooks/restoreBinaryDataId.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/executionLifecycleHooks/restoreBinaryDataId.ts b/packages/cli/src/executionLifecycleHooks/restoreBinaryDataId.ts index 66c5c91b4f2f7..c43788c09428c 100644 --- a/packages/cli/src/executionLifecycleHooks/restoreBinaryDataId.ts +++ b/packages/cli/src/executionLifecycleHooks/restoreBinaryDataId.ts @@ -20,7 +20,7 @@ export async function restoreBinaryDataId(run: IRun, executionId: string) { const { runData } = run.data.resultData; const promises = Object.keys(runData).map(async (nodeName) => { - const binaryDataId = runData[nodeName]?.[0]?.data?.main?.[0]?.[0]?.binary?.data.id; + const binaryDataId = runData[nodeName]?.[0]?.data?.main?.[0]?.[0]?.binary?.data?.id; if (!binaryDataId) return; From e2af7ef31abf089b6f9a4d0be78b0ceb935401cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Thu, 12 Oct 2023 16:15:39 +0200 Subject: [PATCH 2/2] test(core): Add tests for endless execution issue (#7420) The first test ("itemless case") was originally added [here](https://github.com/n8n-io/n8n/pull/7305/files#diff-7bc4c6fd25a41ea39cef04208c96965f55787e1983e9df748fcd923672959f8bL24) but likely removed on accident. --- .../cli/test/unit/execution.lifecycle.test.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/cli/test/unit/execution.lifecycle.test.ts b/packages/cli/test/unit/execution.lifecycle.test.ts index 611c10496d914..c41465c8e508a 100644 --- a/packages/cli/test/unit/execution.lifecycle.test.ts +++ b/packages/cli/test/unit/execution.lifecycle.test.ts @@ -101,6 +101,32 @@ for (const mode of ['filesystem-v2', 's3'] as const) { expect(binaryDataService.rename).not.toHaveBeenCalled(); expect(getDataId(run, 'json')).toBe(dataId); }); + + it('should do nothing on itemless case', async () => { + const executionId = '999'; + + const promise = restoreBinaryDataId(toIRun(), executionId); + + await expect(promise).resolves.not.toThrow(); + + expect(binaryDataService.rename).not.toHaveBeenCalled(); + }); + + it('should do nothing if data is undefined', async () => { + const executionId = '999'; + + const run = toIRun({ + json: { + data: undefined, + }, + }); + + const promise = restoreBinaryDataId(run, executionId); + + await expect(promise).resolves.not.toThrow(); + + expect(binaryDataService.rename).not.toHaveBeenCalled(); + }); }); }); }