From 33e5ed71809d3f449cd304586ef639234a38c2a8 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Tue, 30 May 2023 11:55:58 +1000 Subject: [PATCH] fix(ui): fix edge case in nodes graph building Inputs with explicit values are validated by pydantic even if they also have a connection (which is the actual value that is used). Fix this by omitting explicit values for inputs that have a connection. --- .../util/graphBuilders/buildNodesGraph.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildNodesGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildNodesGraph.ts index eef7379624..6a700d4813 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildNodesGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildNodesGraph.ts @@ -1,8 +1,9 @@ import { Graph } from 'services/api'; import { v4 as uuidv4 } from 'uuid'; -import { cloneDeep, reduce } from 'lodash-es'; +import { cloneDeep, forEach, omit, reduce, values } from 'lodash-es'; import { RootState } from 'app/store/store'; import { InputFieldValue } from 'features/nodes/types/types'; +import { AnyInvocation } from 'services/events/types'; /** * We need to do special handling for some fields @@ -89,6 +90,24 @@ export const buildNodesGraph = (state: RootState): Graph => { [] ); + /** + * Omit all inputs that have edges connected. + * + * Fixes edge case where the user has connected an input, but also provided an invalid explicit, + * value. + * + * In this edge case, pydantic will invalidate the node based on the invalid explicit value, + * even though the actual value that will be used comes from the connection. + */ + parsedEdges.forEach((edge) => { + const destination_node = parsedNodes[edge.destination.node_id]; + const field = edge.destination.field; + parsedNodes[edge.destination.node_id] = omit( + destination_node, + field + ) as AnyInvocation; + }); + // Assemble! const graph = { id: uuidv4(),