diff --git a/packages/cli/src/ActiveExecutions.ts b/packages/cli/src/ActiveExecutions.ts index ce2c1339b9c53..7ee4f3570290a 100644 --- a/packages/cli/src/ActiveExecutions.ts +++ b/packages/cli/src/ActiveExecutions.ts @@ -47,19 +47,11 @@ export class ActiveExecutions { let executionStatus: ExecutionStatus = executionId ? 'running' : 'new'; const mode = executionData.executionMode; - const runExecutionData = executionData.executionData; - - if (!runExecutionData) { - throw new ApplicationError('Cannot add active execution without execution data', { - extra: { workflowId: executionData.workflowData.id }, - }); - } - if (executionId === undefined) { // Is a new execution so save in DB const fullExecutionData: ExecutionPayload = { - data: runExecutionData, + data: executionData.executionData!, mode, finished: false, startedAt: new Date(), @@ -91,7 +83,7 @@ export class ActiveExecutions { const execution: Pick = { id: executionId, - data: runExecutionData, + data: executionData.executionData!, waitTill: null, status: executionStatus, }; diff --git a/packages/cli/src/databases/repositories/execution.repository.ts b/packages/cli/src/databases/repositories/execution.repository.ts index 4e9977c4042f5..94a1a520e1888 100644 --- a/packages/cli/src/databases/repositories/execution.repository.ts +++ b/packages/cli/src/databases/repositories/execution.repository.ts @@ -43,6 +43,8 @@ import { ExecutionDataRepository } from './executionData.repository'; import { Logger } from '@/Logger'; import type { ExecutionSummaries } from '@/executions/execution.types'; import { PostgresLiveRowsRetrievalError } from '@/errors/postgres-live-rows-retrieval.error'; +import { separate } from '@/utils'; +import { ErrorReporterProxy as ErrorReporter } from 'n8n-workflow'; export interface IGetExecutionsQueryFilter { id?: FindOperator | string; @@ -156,7 +158,9 @@ export class ExecutionRepository extends Repository { const executions = await this.find(queryParams); if (options?.includeData && options?.unflattenData) { - return executions.map((execution) => { + const [valid, invalid] = separate(executions, (e) => e.executionData !== null); + this.reportInvalidExecutions(invalid); + return valid.map((execution) => { const { executionData, metadata, ...rest } = execution; return { ...rest, @@ -166,7 +170,9 @@ export class ExecutionRepository extends Repository { } as IExecutionResponse; }); } else if (options?.includeData) { - return executions.map((execution) => { + const [valid, invalid] = separate(executions, (e) => e.executionData !== null); + this.reportInvalidExecutions(invalid); + return valid.map((execution) => { const { executionData, metadata, ...rest } = execution; return { ...rest, @@ -183,6 +189,16 @@ export class ExecutionRepository extends Repository { }); } + reportInvalidExecutions(executions: ExecutionEntity[]) { + if (executions.length === 0) return; + + ErrorReporter.error( + new ApplicationError('Found executions without executionData', { + extra: { executionIds: executions.map(({ id }) => id) }, + }), + ); + } + async findSingleExecution( id: string, options?: { diff --git a/packages/cli/test/unit/ActiveExecutions.test.ts b/packages/cli/test/unit/ActiveExecutions.test.ts index 81c525531ed39..b2454de87c5e1 100644 --- a/packages/cli/test/unit/ActiveExecutions.test.ts +++ b/packages/cli/test/unit/ActiveExecutions.test.ts @@ -137,7 +137,6 @@ function mockExecutionData(): IWorkflowExecutionDataProcess { nodes: [], connections: {}, }, - executionData: { resultData: { runData: {} } }, userId: uuid(), }; }