fix: Load workflows with unconnected Switch outputs (#12020)

This commit is contained in:
Mutasem Aldmour
2024-12-04 13:44:25 +01:00
committed by GitHub
parent bd693162b8
commit abc851c0cf
24 changed files with 324 additions and 89 deletions

View File

@@ -364,7 +364,8 @@ export interface ICredentialDataDecryptedObject {
// First array index: The output/input-index (if node has multiple inputs/outputs of the same type)
// Second array index: The different connections (if one node is connected to multiple nodes)
export type NodeInputConnections = IConnection[][];
// Any index can be null, for example in a switch node with multiple indexes some of which are not connected
export type NodeInputConnections = Array<IConnection[] | null>;
export interface INodeConnection {
sourceIndex: number;

View File

@@ -194,7 +194,7 @@ export class Workflow {
returnConnection[connectionInfo.node][connectionInfo.type].push([]);
}
returnConnection[connectionInfo.node][connectionInfo.type][connectionInfo.index].push({
returnConnection[connectionInfo.node][connectionInfo.type][connectionInfo.index]?.push({
node: sourceNode,
type,
index: parseInt(inputIndex, 10),
@@ -551,18 +551,18 @@ export class Workflow {
let type: string;
let sourceIndex: string;
let connectionIndex: string;
let connectionData: IConnection;
let connectionData: IConnection | undefined;
for (sourceNode of Object.keys(this.connectionsBySourceNode)) {
for (type of Object.keys(this.connectionsBySourceNode[sourceNode])) {
for (sourceIndex of Object.keys(this.connectionsBySourceNode[sourceNode][type])) {
for (connectionIndex of Object.keys(
this.connectionsBySourceNode[sourceNode][type][parseInt(sourceIndex, 10)],
this.connectionsBySourceNode[sourceNode][type][parseInt(sourceIndex, 10)] || [],
)) {
connectionData =
this.connectionsBySourceNode[sourceNode][type][parseInt(sourceIndex, 10)][
this.connectionsBySourceNode[sourceNode][type][parseInt(sourceIndex, 10)]?.[
parseInt(connectionIndex, 10)
];
if (connectionData.node === currentName) {
if (connectionData?.node === currentName) {
connectionData.node = newName;
}
}
@@ -615,7 +615,7 @@ export class Workflow {
const returnNodes: string[] = [];
let addNodes: string[];
let connectionsByIndex: IConnection[];
let connectionsByIndex: IConnection[] | null;
for (
let connectionIndex = 0;
connectionIndex < this.connectionsByDestinationNode[nodeName][type].length;
@@ -627,7 +627,7 @@ export class Workflow {
}
connectionsByIndex = this.connectionsByDestinationNode[nodeName][type][connectionIndex];
// eslint-disable-next-line @typescript-eslint/no-loop-func
connectionsByIndex.forEach((connection) => {
connectionsByIndex?.forEach((connection) => {
if (checkedNodes.includes(connection.node)) {
// Node got checked already before
return;
@@ -742,7 +742,7 @@ export class Workflow {
checkedNodes.push(nodeName);
connections[nodeName][type].forEach((connectionsByIndex) => {
connectionsByIndex.forEach((connection) => {
connectionsByIndex?.forEach((connection) => {
if (checkedNodes.includes(connection.node)) {
// Node got checked already before
return;
@@ -839,7 +839,7 @@ export class Workflow {
}
connections[curr.name][type].forEach((connectionsByIndex) => {
connectionsByIndex.forEach((connection) => {
connectionsByIndex?.forEach((connection) => {
queue.push({
name: connection.node,
indicies: [connection.index],
@@ -943,6 +943,10 @@ export class Workflow {
let outputIndex: INodeConnection | undefined;
for (const connectionsByIndex of this.connectionsByDestinationNode[nodeName][type]) {
if (!connectionsByIndex) {
continue;
}
for (
let destinationIndex = 0;
destinationIndex < connectionsByIndex.length;

View File

@@ -990,11 +990,8 @@ function alphanumericId() {
const chooseRandomly = <T>(array: T[]) => array[randomInt(array.length)];
function generateTestWorkflowAndRunData(): { workflow: IWorkflowBase; runData: IRunData } {
const workflow: IWorkflowBase = {
meta: {
instanceId: 'a786b722078489c1fa382391a9f3476c2784761624deb2dfb4634827256d51a0',
},
function generateTestWorkflowAndRunData(): { workflow: Partial<IWorkflowBase>; runData: IRunData } {
const workflow: Partial<IWorkflowBase> = {
nodes: [
{
parameters: {},