Skip to content

Commit

Permalink
fix(core): Account for itemless case on restoring binary data ID (#7305)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov authored and netroy committed Oct 4, 2023
1 parent 43534ab commit c479d86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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 || !isMissingExecutionId(binaryDataId)) return;

Expand Down
12 changes: 11 additions & 1 deletion packages/cli/test/unit/execution.lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BinaryDataService } from 'n8n-core';
import { mockInstance } from '../integration/shared/utils/mocking';
import type { IRun } from 'n8n-workflow';

function toIRun(item: object) {
function toIRun(item?: object) {
return {
data: {
resultData: {
Expand Down Expand Up @@ -84,4 +84,14 @@ describe('restoreBinaryDataId()', () => {
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();
});
});

0 comments on commit c479d86

Please sign in to comment.