fix(core): Prevent workflow history saving error from happening (#7812)
When performing actions such as renaming a workflow or updating its settings, n8n errors with "Failed to save workflow version" in the console although the saving process was successful. We are now correctly checking whether `nodes` and `connections` exist and only then save a snapshot. Github issue / Community forum post (link here to close automatically):
This commit is contained in:
@@ -66,7 +66,10 @@ export class WorkflowHistoryService {
|
||||
}
|
||||
|
||||
async saveVersion(user: User, workflow: WorkflowEntity, workflowId: string) {
|
||||
if (isWorkflowHistoryEnabled()) {
|
||||
// On some update scenarios, `nodes` and `connections` are missing, such as when
|
||||
// changing workflow settings or renaming. In these cases, we don't want to save
|
||||
// a new version
|
||||
if (isWorkflowHistoryEnabled() && workflow.nodes && workflow.connections) {
|
||||
try {
|
||||
await this.workflowHistoryRepository.insert({
|
||||
authors: user.firstName + ' ' + user.lastName,
|
||||
|
||||
@@ -4,6 +4,7 @@ import { NodeApiError, ErrorReporterProxy as ErrorReporter, Workflow } from 'n8n
|
||||
import type { FindManyOptions, FindOptionsSelect, FindOptionsWhere, UpdateResult } from 'typeorm';
|
||||
import { In, Like } from 'typeorm';
|
||||
import pick from 'lodash/pick';
|
||||
import omit from 'lodash/omit';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
||||
import * as WorkflowHelpers from '@/WorkflowHelpers';
|
||||
@@ -230,21 +231,9 @@ export class WorkflowsService {
|
||||
);
|
||||
}
|
||||
|
||||
let onlyActiveUpdate = false;
|
||||
|
||||
if (
|
||||
(Object.keys(workflow).length === 3 &&
|
||||
workflow.id !== undefined &&
|
||||
workflow.versionId !== undefined &&
|
||||
workflow.active !== undefined) ||
|
||||
(Object.keys(workflow).length === 2 &&
|
||||
workflow.versionId !== undefined &&
|
||||
workflow.active !== undefined)
|
||||
) {
|
||||
// we're just updating the active status of the workflow, don't update the versionId
|
||||
onlyActiveUpdate = true;
|
||||
} else {
|
||||
// Update the workflow's version
|
||||
if (Object.keys(omit(workflow, ['id', 'versionId', 'active'])).length > 0) {
|
||||
// Update the workflow's version when changing properties such as
|
||||
// `name`, `pinData`, `nodes`, `connections`, `settings` or `tags`
|
||||
workflow.versionId = uuid();
|
||||
logger.verbose(
|
||||
`Updating versionId for workflow ${workflowId} for user ${user.id} after saving`,
|
||||
@@ -320,7 +309,7 @@ export class WorkflowsService {
|
||||
);
|
||||
}
|
||||
|
||||
if (!onlyActiveUpdate && workflow.versionId !== shared.workflow.versionId) {
|
||||
if (workflow.versionId !== shared.workflow.versionId) {
|
||||
await Container.get(WorkflowHistoryService).saveVersion(user, workflow, workflowId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user