Skip to content

Defer networkx import for schema generation - #9457

Open
DustyShoe wants to merge 2 commits into
invoke-ai:mainfrom
DustyShoe:fix/lazy-networkx-graph-import
Open

Defer networkx import for schema generation#9457
DustyShoe wants to merge 2 commits into
invoke-ai:mainfrom
DustyShoe:fix/lazy-networkx-graph-import

Conversation

@DustyShoe

@DustyShoe DustyShoe commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Defer networkx import in invokeai.app.services.shared.graph until graph functionality actually touches nx.
  • Quote nx.DiGraph type annotations so importing the module does not require networkx at annotation evaluation time.
  • Add a regression test proving the graph module can be imported when networkx import is unavailable.

Context

PR #9091 exposed an existing CI fragility in the frontend typegen job. scripts/generate_openapi_schema.py imports the FastAPI app, which imports invokeai.app.services.shared.graph, and that module imported networkx at module load time. In CI environments where networkx is not installed, schema generation exits before emitting JSON, then pnpm typegen fails with Unexpected end of JSON input because it receives no schema.

This PR fixes the import-time coupling by deferring the networkx import until graph functionality actually uses it.

Validation

  • uv run ../../../scripts/generate_openapi_schema.py | pnpm typegen
  • uv run pytest tests/test_imports.py -k graph_module_import_does_not_require_networkx -q
  • uv run pytest tests/test_node_graph.py -q
  • uv tool run ruff@0.11.2 check invokeai/app/services/shared/graph.py tests/test_imports.py
  • uv lock --check
  • git diff --check

@DustyShoe
DustyShoe marked this pull request as ready for review August 3, 2026 21:05
@github-actions github-actions Bot added python PRs that change python files services PRs that change app services python-tests PRs that change python tests labels Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python PRs that change python files python-tests PRs that change python tests services PRs that change app services

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant