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.
This commit is contained in:
psychedelicious 2023-05-30 11:55:58 +10:00 committed by Kent Keirsey
parent 2067757fab
commit 33e5ed7180

View File

@ -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(),