Skip to content

Commit

Permalink
fix(core): fix workflow hasing for MySQL (#4491)
Browse files Browse the repository at this point in the history
* 🐛 Alphabetize node keys

* 🔥 Remove excess braces
  • Loading branch information
ivov authored Nov 1, 2022
1 parent e1a3f56 commit 2b5613e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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],
}),
{},
);

0 comments on commit 2b5613e

Please sign in to comment.