Repository navigation
Conversation
…puts Collector output validation took the first type argument of the destination as its item type, so Union[list[X], X] and Optional[list[X]] inputs raised a TypeError on mismatched items and enqueue returned 500. Read item types from the list branches instead.
1 task done
JPPhoto
requested changes
Oct 14, 2026
JPPhoto
left a comment
Collaborator
There was a problem hiding this comment.
Hi @unmarco, thanks for the PR.
In my review, I uncovered this:
invokeai/app/services/shared/graph_validation.py:2340: For a collector ofDerived(Base)targetinglist[Union[Base, str]], the union-aware subtype check misses the subclass, and the class guard skipsissubclass; validation rejects a valid edge. The base accepted it. Effect: valid workflows cannot connect this collector. Likelihood: plausible when a node declares union-typed list items. Recovery: manual graph or type workaround. Test: the candidate validator reproduces the rejection; add aGraph.add_edgeregression for this case.
Please add the test and fix the code and perform another self-review, then re-request review from me when complete.
This was referenced Oct 14, 2026
A collection input like list[Union[Base, str]] now matches a collector of Derived(Base) again: the class guard checks issubclass against each union member. Adds Graph.add_edge regressions for typing.Union and PEP 604 unions.
Contributor
Author
|
Thanks for catching this. Fixed in 796b0f8.
I added Self-review and checks:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A Collect node connected to an input typed
Union[list[X], X]orOptional[list[X]]with mismatched items crashed graph validation withTypeError: issubclass() argument 2 cannot be a parameterized generic, so enqueue returned 500 (which webv2 retries indefinitely) instead of 422.Collector output validation now reads the destination's item types with the existing
extract_collection_item_types(), which handles list branches inside unions, and only callsissubclass()on real classes. Mismatched items are rejected with the usual "matching type" error; matching items are accepted as before.Before:
integer, integer → collect → metadata.items→TypeError→ HTTP 500After:
InvalidEdgeError: Collector outputs must connect to a collection input with a matching type→ HTTP 422Related Issues / Discussions
Closes #9852
QA Instructions
uv run --no-sync pytest tests/test_node_graph.py -k "union_input or optional_list_input or list_first_union": the two new rejection cases fail onmainwith theTypeErrorand pass with this change; the two acceptance cases pass on both.uv run --no-sync pytest tests/test_node_graph.py tests/test_graph_execution_state.py tests/app/services/shared tests/app/services/test_workflow_graph_builder.py tests/app/routers/test_session_queue_sanitization.py -n 4: 1753 passed, 22 skipped, 2 xfailed.uv tool run ruff@0.11.2 check/format --checkon the changed files: clean.Batch.model_validateon the repro graph from the issue:ValidationError(422) instead ofTypeError(500). Also checkedmerge_metadata.collectionandcore_metadata.loras: both now raiseInvalidEdgeError.pytest -n logicalsuite, and no browser check (no UI change).Review
No blocking findings. Intended behaviour changes beyond the crash, all toward reading the annotation correctly:
Union[int, list[str]]with integer items was accepted, because the scalar happened to come first. It is now rejected.Union[list[A], list[B]]matches if any list branch matches, not only the first.Optional[list[Any]]/Union[list[Any], X]accept collected items, typed or untyped, aslist[Any]already did. Before, they crashed or were rejected. No core node uses such an annotation today.Checklist
What's Newcopy (if doing a release after this PR)Need help on this PR? Tag
@codesmith-botwith what you need.