Circular migration dependencies make forwards_plan/backwards_plan hang instead of raising
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- Mezza giornata
- Idoneità per principianti
- 68/100
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):
- https://github.com/tortoise/tortoise-orm/blob/581557399f13994d0249f3e8c9f59ee02052c4b1/tortoise/migrations/graph.py#L108-L111 (
validate_consistency) - https://github.com/tortoise/tortoise-orm/blob/581557399f13994d0249f3e8c9f59ee02052c4b1/tortoise/migrations/graph.py#L139-L154 (
_iterative_dfs)
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
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di tortoise/tortoise-orm
-
pydantic_model_creator returns a cached class that ignores model_config, validators and moduleForse già presa @moneebullah25 l’ha presa 6 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
tortoise/tortoise-orm#2310 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
tortoise/tortoise-orm#668 ·
I maintainer di solito rispondono entro 2 giorni
-
refresh_from_db silently ignores fields supplied as an iteratorForse già presa @IlyaKhalafi l’ha presa 1 giorno fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
tortoise/tortoise-orm#2341 ·
I maintainer di solito rispondono entro 2 giorni
-
Renamed fields break dict(model) and default values_listForse già presa @IlyaKhalafi l’ha presa 1 giorno fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
tortoise/tortoise-orm#2337 ·
I maintainer di solito rispondono entro 2 giorni
-
Reverse relation filters use attribute names for SQL columnsForse già presa @IlyaKhalafi l’ha presa 1 giorno fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
tortoise/tortoise-orm#2336 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di tortoise/tortoise-orm
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
aws-samples/sample-per-model-bedrock#261 ·
I maintainer di solito rispondono entro 1 giorno
-
[UI/Accessibility] Low contrast text visibility in country selection dropdown on settings pageAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
pwncollege/dojo#1188 ·
I maintainer di solito rispondono entro 1 giorno
-
bug launcher packaging
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
tenstorrent/tt-studio#1426 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
python-attrs/cattrs#796 ·
I maintainer di solito rispondono entro 1 giorno