Skip to content

Commit

Permalink
fix(core): Handle connections for missing nodes in a workflow (#13362)
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy authored Feb 19, 2025
1 parent 6ef9ae1 commit 1e5feb1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/workflow/src/Workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,9 @@ export class Workflow {
return;
}

// Ignore connections for nodes that don't exist in this workflow
if (!(connection.node in this.nodes)) return;

addNodes = this.getHighestNode(connection.node, undefined, checkedNodes);

if (addNodes.length === 0) {
Expand Down
27 changes: 26 additions & 1 deletion packages/workflow/test/Workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2201,7 +2201,7 @@ describe('Workflow', () => {
expect(result).toEqual([targetNode.name]);
});

test('should handle connections to nodes not defined in workflow', () => {
test('should handle connections to nodes that are not defined in the workflow', () => {
const node1 = createNode('Node1');
const targetNode = createNode('TargetNode');

Expand All @@ -2226,6 +2226,31 @@ describe('Workflow', () => {

expect(result).toEqual([targetNode.name]);
});

test('should handle connections from nodes that are not defined in the workflow', () => {
const node1 = createNode('Node1');
const targetNode = createNode('TargetNode');

const connections = {
Node1: {
main: [[{ node: 'TargetNode', type: NodeConnectionType.Main, index: 0 }]],
},
NonExistentNode: {
main: [[{ node: 'TargetNode', type: NodeConnectionType.Main, index: 0 }]],
},
};

const workflow = new Workflow({
id: 'test',
nodes: [node1, targetNode],
connections,
active: false,
nodeTypes,
});

const result = workflow.getHighestNode(targetNode.name);
expect(result).toEqual([node1.name]);
});
});

describe('getParentMainInputNode', () => {
Expand Down

0 comments on commit 1e5feb1

Please sign in to comment.