Skip to content

Commit a2ddecf

Browse files
workflow: ensure we handle trailing null values (#13616)
* handle null inputs * format * add changeset * lint * init with default * add changeset * tweak * format * add changeset * remove empty --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
1 parent 3b12faa commit a2ddecf

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

.changeset/three-tigers-fold.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@gradio/workflowcanvas": minor
3+
"gradio": minor
4+
---
5+
6+
feat:workflow: ensure we handle trailing null values

js/workflowcanvas/workflow/WorkflowCanvas.svelte

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
WFEdge,
4646
NodeStatus,
4747
NodeRole,
48+
NodeDataValue,
4849
Workflow
4950
} from "./workflow-types";
5051
import { executeWorkflow } from "./workflow-executor";
@@ -490,6 +491,11 @@
490491
template.height
491492
);
492493
const newId = addNode("reference", template, x, y);
494+
const port = node.inputs.find((p) => p.id === portId);
495+
if (port?.default_value !== undefined) {
496+
const outId = template.outputs[0]?.id ?? "out";
497+
updateNodeData(newId, outId, port.default_value as NodeDataValue);
498+
}
493499
addEdge({
494500
from_node_id: newId,
495501
from_port_id: "out",
@@ -2032,6 +2038,13 @@
20322038
inStartY + i * (compH + compGap)
20332039
);
20342040
const cId = addNode("reference", comp, cx, cy);
2041+
if (port.default_value !== undefined) {
2042+
updateNodeData(
2043+
cId,
2044+
comp.outputs[0]?.id ?? "out",
2045+
port.default_value as NodeDataValue
2046+
);
2047+
}
20352048
addEdge({
20362049
from_node_id: cId,
20372050
from_port_id: "out",

js/workflowcanvas/workflow/workflow-store.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ export function sanitize_for_save(wf: Workflow): Workflow {
9494
}
9595

9696
// ─── Actions ────────────────────────────────────────────────────────────────
97+
const PORT_DEFAULTS: Partial<Record<PortType, NodeDataValue>> = {
98+
boolean: false,
99+
number: 0,
100+
text: ""
101+
};
97102

98103
function addReference(
99104
template: Omit<ReferenceNode, "id" | "role" | "x" | "y" | "data">,
@@ -102,9 +107,11 @@ function addReference(
102107
): string {
103108
const id = uuid();
104109
const data: Record<string, NodeDataValue> = {};
105-
for (const port of template.inputs) {
110+
for (const port of [...template.inputs, ...template.outputs]) {
106111
if (port.default_value !== undefined) {
107112
data[port.id] = port.default_value as NodeDataValue;
113+
} else if (port.type in PORT_DEFAULTS) {
114+
data[port.id] ??= PORT_DEFAULTS[port.type]!;
108115
}
109116
}
110117
const node: ReferenceNode = {

0 commit comments

Comments
 (0)