fix(core): Revert transactions until we remove the legacy sqlite driver (#10299)
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2024-08-05 18:10:16 +02:00 committed by GitHub
parent 74e154b130
commit 1eba7c3c76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 10 additions and 64 deletions

View file

@ -73,6 +73,7 @@ jobs:
env:
N8N_ENCRYPTION_KEY: ${{secrets.ENCRYPTION_KEY}}
SKIP_STATISTICS_EVENTS: true
DB_SQLITE_POOL_SIZE: 4
# -
# name: Export credentials
# if: always()

View file

@ -274,23 +274,16 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
* Insert a new execution and its execution data using a transaction.
*/
async createNewExecution(execution: ExecutionPayload): Promise<string> {
return await this.manager.transaction(async (transactionManager) => {
const { data, workflowData, ...rest } = execution;
const insertResult = await transactionManager.insert(ExecutionEntity, rest);
const { id: executionId } = insertResult.identifiers[0] as { id: string };
const { connections, nodes, name, settings } = workflowData ?? {};
await this.executionDataRepository.createExecutionDataForExecution(
{
executionId,
workflowData: { connections, nodes, name, settings, id: workflowData.id },
data: stringify(data),
},
transactionManager,
);
return String(executionId);
const { data, workflowData, ...rest } = execution;
const { identifiers: inserted } = await this.insert(rest);
const { id: executionId } = inserted[0] as { id: string };
const { connections, nodes, name, settings } = workflowData ?? {};
await this.executionDataRepository.insert({
executionId,
workflowData: { connections, nodes, name, settings, id: workflowData.id },
data: stringify(data),
});
return String(executionId);
}
async markAsCrashed(executionIds: string | string[]) {

View file

@ -1,32 +1,13 @@
import { Service } from 'typedi';
import type { EntityManager } from '@n8n/typeorm';
import type { IWorkflowBase } from 'n8n-workflow';
import { DataSource, In, Repository } from '@n8n/typeorm';
import { ExecutionData } from '../entities/ExecutionData';
export interface CreateExecutionDataOpts extends Pick<ExecutionData, 'data' | 'executionId'> {
workflowData: Pick<IWorkflowBase, 'connections' | 'nodes' | 'name' | 'settings' | 'id'>;
}
@Service()
export class ExecutionDataRepository extends Repository<ExecutionData> {
constructor(dataSource: DataSource) {
super(ExecutionData, dataSource.manager);
}
async createExecutionDataForExecution(
executionData: CreateExecutionDataOpts,
transactionManager: EntityManager,
) {
const { data, executionId, workflowData } = executionData;
return await transactionManager.insert(ExecutionData, {
executionId,
data,
workflowData,
});
}
async findByExecutionIds(executionIds: string[]) {
return await this.find({
select: ['workflowData'],

View file

@ -52,34 +52,5 @@ describe('ExecutionRepository', () => {
});
expect(executionData?.data).toEqual('[{"resultData":"1"},{}]');
});
it('should not create execution if execution data insert fails', async () => {
const executionRepo = Container.get(ExecutionRepository);
const executionDataRepo = Container.get(ExecutionDataRepository);
const workflow = await createWorkflow({ settings: { executionOrder: 'v1' } });
jest
.spyOn(executionDataRepo, 'createExecutionDataForExecution')
.mockRejectedValueOnce(new Error());
await expect(
async () =>
await executionRepo.createNewExecution({
workflowId: workflow.id,
data: {
//@ts-expect-error This is not needed for tests
resultData: {},
},
workflowData: workflow,
mode: 'manual',
startedAt: new Date(),
status: 'new',
finished: false,
}),
).rejects.toThrow();
const executionEntities = await executionRepo.find();
expect(executionEntities).toBeEmptyArray();
});
});
});