Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix workflow hasing for MySQL #4491

Merged
merged 2 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/cli/src/databases/entities/WorkflowEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { SharedWorkflow } from './SharedWorkflow';
import { objectRetriever, sqlite } from '../utils/transformers';
import { AbstractEntity, jsonColumnType } from './AbstractEntity';
import type { IWorkflowDb } from '../../Interfaces';
import { alphabetizeKeys } from '../../utils';

@Entity()
export class WorkflowEntity extends AbstractEntity implements IWorkflowDb {
Expand Down Expand Up @@ -103,7 +104,7 @@ export class WorkflowEntity extends AbstractEntity implements IWorkflowDb {
const state = JSON.stringify({
name,
active,
nodes,
nodes: nodes ? nodes.map(alphabetizeKeys) : [],
connections,
settings,
staticData,
Expand Down
13 changes: 13 additions & 0 deletions packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { CliWorkflowOperationError, SubworkflowOperationError } from 'n8n-workflow';
import type { INode } from 'n8n-workflow';

Expand Down Expand Up @@ -28,3 +29,15 @@ function findWorkflowStart(executionMode: 'integrated' | 'cli') {
export const findSubworkflowStart = findWorkflowStart('integrated');

export const findCliWorkflowStart = findWorkflowStart('cli');

export const alphabetizeKeys = (obj: INode) =>
Object.keys(obj)
.sort()
.reduce<Partial<INode>>(
(acc, key) => ({
...acc,
// @ts-expect-error @TECH_DEBT Adding index signature to INode causes type issues downstream
[key]: obj[key],
}),
{},
);