Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
Fix collector iterator numeric type inference
JPPhoto7855613ebac2
diff --git a/invokeai/app/services/shared/README.md b/invokeai/app/services/shared/README.mdindex f05a893868..249343db42 100644--- a/invokeai/app/services/shared/README.md+++ b/invokeai/app/services/shared/README.md@@ -207,10 +207,12 @@ Runs a sequence of checks:hooks; the current condition value does not narrow the possible types.- Collector item/collection checks and iterator collection checks also use the resolved branch sources. This allowsmatching string branches to feed a string collector without an intermediate string node.+ - Iterators over collectors validate their item consumers against the same inferred collector root type. Mixed+ `int` and `float` items therefore require consumers compatible with `float`.- If a branch is unresolved, retain the declared output compatibility behavior (`Any` for collector typeinference). The graph's separate DAG check rejects cycles before projection.- - Collectors can combine `int` and `float` items as `float`, preserving numeric workflows whose downstream- consumers accept floats; unrelated mixed item types remain invalid.+ - This widens compatibility: a direct collector with both `int` and `float` items, previously rejected, now resolves+ to `float`. Its downstream consumers must accept floats; unrelated mixed item types remain invalid.- Ordinary source ports use the direct compatibility path with already resolved nodes, without If traversal orprojection allocations.diff --git a/invokeai/app/services/shared/graph_validation.py b/invokeai/app/services/shared/graph_validation.pyindex c819b56451..cf50a0f256 100644--- a/invokeai/app/services/shared/graph_validation.py+++ b/invokeai/app/services/shared/graph_validation.py@@ -2044,16 +2044,14 @@ class Graph(BaseModel):def _get_collector_input_root_type(self, node_id: str) -> Any | None:input_types = self._resolve_collector_input_types(node_id)- non_any_input_types = {t for t in input_types if t != Any}- if len(non_any_input_types) == 0 and Any in input_types:+ has_multiple_root_types, input_root_type = self._get_collector_input_root_type_from_resolved_types(input_types)+ if has_multiple_root_types:return Any- if len(non_any_input_types) == 0:- return None-- root_types = self._get_type_tree_root_types(non_any_input_types)- if len(root_types) != 1:+ if input_root_type is not None:+ return input_root_type+ if Any in input_types:return Any- return root_types[0]+ return Nonedef _get_collector_connections(self,diff --git a/tests/test_node_graph.py b/tests/test_node_graph.pyindex ede560ddce..ee4a295b11 100644--- a/tests/test_node_graph.py+++ b/tests/test_node_graph.py@@ -1081,21 +1081,6 @@ def test_graph_collector_accepts_if_output_when_both_branches_have_matching_typegraph.add_edge(create_edge(collector.id, "collection", consumer.id, "collection"))-def test_graph_effective_if_output_deduplicates_shared_branch_sources():- graph = Graph(- nodes={- "value": StringInvocation(id="value", value="shared"),- "if": IfInvocation(id="if"),- },- edges=[- create_edge("value", "value", "if", "true_input"),- create_edge("value", "value", "if", "false_input"),- ],- )-- assert graph._get_effective_output_connections("if", "value") == [EdgeConnection(node_id="value", field="value")]--def test_graph_collectors_accept_if_output_with_and_without_a_string_collection_seed():graph = Graph()true_value = StringInvocation(id="true", value="true")@@ -1229,6 +1214,34 @@ def test_graph_accepts_and_runs_mixed_numeric_if_branches_through_iterator(condiassert isinstance(output.value, float)[email protected]("through_if", [False, True], ids=["direct collector", "If branches"])+def test_graph_rejects_integer_iterator_output_for_mixed_numeric_collector(through_if: bool):+ integer_value = IntegerInvocation(id="integer", value=2)+ float_value = FloatInvocation(id="float", value=3.5)+ collector = CollectInvocation(id="collect")+ iterator = IterateInvocation(id="iterate")+ integer_consumer = IntegerInvocation(id="integer_consumer")+ nodes = [integer_value, float_value, collector, iterator, integer_consumer]+ graph = Graph(nodes={node.id: node for node in nodes})++ if through_if:+ if_node = IfInvocation(id="if")+ graph.add_node(if_node)+ graph.add_edge(create_edge(integer_value.id, "value", if_node.id, "true_input"))+ graph.add_edge(create_edge(float_value.id, "value", if_node.id, "false_input"))+ graph.add_edge(create_edge(if_node.id, "value", collector.id, "item"))+ else:+ graph.add_edge(create_edge(integer_value.id, "value", collector.id, "item"))+ graph.add_edge(create_edge(float_value.id, "value", collector.id, "item"))++ graph.add_edge(create_edge(collector.id, "collection", iterator.id, "collection"))+ invalid_output_edge = create_edge(iterator.id, "item", integer_consumer.id, "value")+ with pytest.raises(InvalidEdgeError, match="Iterator collection type must match all iterator output types"):+ graph.add_edge(invalid_output_edge)++ assert invalid_output_edge not in graph.edges++def test_graph_rejects_iterator_consumers_incompatible_with_if_collector_branches():graph = Graph()string_value = StringInvocation(id="string", value="text")