Skip to content

Commit

Permalink
fix: Prevent undefined issues when restoring binary data (#7419)
Browse files Browse the repository at this point in the history
Github issue / Community forum post (link here to close automatically):

---------

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
  • Loading branch information
2 people authored and elsmr committed Oct 19, 2023
1 parent f945306 commit e7f92ba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
26 changes: 26 additions & 0 deletions packages/cli/test/unit/execution.lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
}

0 comments on commit e7f92ba

Please sign in to comment.