Defer networkx import for schema generation - #9457
Open
DustyShoe wants to merge 2 commits into
Open
Conversation
DustyShoe
marked this pull request as ready for review
August 3, 2026 21:05
DustyShoe
requested review from
JPPhoto,
Pfannkuchensack,
blessedcoolant,
dunkeroni and
lstein
as code owners
August 3, 2026 21:05
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
networkximport ininvokeai.app.services.shared.graphuntil graph functionality actually touchesnx.nx.DiGraphtype annotations so importing the module does not requirenetworkxat annotation evaluation time.networkximport is unavailable.Context
PR #9091 exposed an existing CI fragility in the frontend typegen job.
scripts/generate_openapi_schema.pyimports the FastAPI app, which importsinvokeai.app.services.shared.graph, and that module importednetworkxat module load time. In CI environments wherenetworkxis not installed, schema generation exits before emitting JSON, thenpnpm typegenfails withUnexpected end of JSON inputbecause it receives no schema.This PR fixes the import-time coupling by deferring the
networkximport until graph functionality actually uses it.Validation
uv run ../../../scripts/generate_openapi_schema.py | pnpm typegenuv run pytest tests/test_imports.py -k graph_module_import_does_not_require_networkx -quv run pytest tests/test_node_graph.py -quv tool run ruff@0.11.2 check invokeai/app/services/shared/graph.py tests/test_imports.pyuv lock --checkgit diff --check