Skip to content

fix(migrations): ignore cross-app edges in leaf_nodes/root_nodes for an app - #2308

Closed
moneebullah25 wants to merge 3 commits into
tortoise:developfrom
moneebullah25:fix/migration-graph-leaf-root-cross-app
Closed

moneebullah25 wants to merge 3 commits into
tortoise:developfrom
moneebullah25:fix/migration-graph-leaf-root-cross-app

Conversation

@moneebullah25

Copy link
Copy Markdown
Contributor

Description

MigrationGraph.leaf_nodes(app_label) and root_nodes(app_label) now ignore edges to or from other apps when an app_label is given. Both methods share one helper. Calls without app_label behave as before.

Motivation and Context

When app B depends on the newest migration of app A, that migration has a child in app B, so leaf_nodes("A") returned nothing. Targets like A.__latest__ (and A.__first__ in the mirrored case) then failed to resolve.

Fixes #2305

How Has This Been Tested?

  • Added test_graph_leaf_and_root_nodes_ignore_cross_app_edges (graph level).
  • Added test_loader_resolves_cross_app_latest_and_first (loader resolving __latest__ / __first__ across apps).
  • Ran python -m pytest tests/migrations/test_runtime_migrations.py -q: 15 passed.
  • With graph.py swapped for the develop version, the new graph test fails, so it covers the bug.
  • Ran ruff check, ruff format --check and codespell on the changed files: pass. The local ruff is 0.15.4 and the pin is 0.15.9.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codspeed

codspeed Bot commented Oct 9, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 24 untouched benchmarks


Comparing moneebullah25:fix/migration-graph-leaf-root-cross-app (052b070) with develop (5815573)

Open in CodSpeed

@moneebullah25

Copy link
Copy Markdown
Contributor Author

Closing this as a duplicate of #2307, which was opened first for the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

leaf_nodes(app_label)/root_nodes(app_label) count cross-app edges, so migrating to app.__latest__ can plan nothing

1 participant