Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Circular migration dependencies make forwards_plan/backwards_plan hang instead of raising

Aperta
#2,304 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@moneebullah25 ci sta già lavorando.

Dal 9/10/2026.

  • #2306 di @moneebullah25 — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
databases

Direzione di ricerca

The bug is in tortoise/migrations/graph.py: validate_consistency() only rejects DummyNode, and _iterative_dfs() marks nodes visited only on post-order pop, so forwards_plan and backwards_plan loop forever on a cycle. Start by running the reproduction script from the issue under a timeout to confirm the hang. Done means a cycle raises a clear error naming the migrations involved, either from validate_consistency or from the DFS, and the reproduction no longer hangs. Add a test with a two-node cycle in the migrations test suite.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

MigrationGraph.validate_consistency() only rejects DummyNodes, so a cycle between migrations is accepted. _iterative_dfs only marks a node as visited when its post-order frame is popped, so on a cycle the same nodes are pushed again and again. forwards_plan and backwards_plan never return and the DFS stack grows without bound.

makemigrations, migrate, plan and sqlmigrate reach these two functions (directly or through the executor / autodetector), so a cyclic migration tree, for example after a bad merge or a hand edit of dependencies, hangs those commands instead of failing.

Code (commit 581557399f13994d0249f3e8c9f59ee02052c4b1):

To Reproduce

import signal
from tortoise.migrations.graph import MigrationGraph, MigrationKey

g = MigrationGraph()
a, b = MigrationKey("x", "a"), MigrationKey("x", "b")
g.add_node(a, None)
g.add_node(b, None)
g.add_dependency(None, a, b)
g.add_dependency(None, b, a)
g.validate_consistency()          # passes, no error
signal.alarm(3)                   # only so the script does not hang forever
g.forwards_plan(a)                # never returns, killed by SIGALRM

Tested on tortoise-orm 1.1.8, develop at 581557399f13994d0249f3e8c9f59ee02052c4b1.

Expected behavior

A clear error naming the cycle (Django raises CircularDependencyError in this situation).

Additional context

I searched upstream issues and PRs (open and closed) for migration cycle/circular/hang reports and found nothing relevant.

One possible approach: track an in-progress set in _iterative_dfs (or run a colouring pass in validate_consistency) and raise when a back-edge is found.

Lingua principale
Python
Stelle
5.6k
Fork
523
Merge medio
2g 18h
PR unite (30g)
12

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tortoise/tortoise-orm

Tutte le issue di tortoise/tortoise-orm

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.