Circular migration dependencies make forwards_plan/backwards_plan hang instead of raising
Los mantenedores suelen responder en 2 días
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- Medio día
- Aptitud para principiantes
- 68/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 5.6k
- Forks
- 523
- Merge medio
- 2 d 18 h
- PR fusionados (30 d)
- 12
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de tortoise/tortoise-orm
-
pydantic_model_creator returns a cached class that ignores model_config, validators and modulePosiblemente ocupada @moneebullah25 la tomó hace 5 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
tortoise/tortoise-orm#2310 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
tortoise/tortoise-orm#668 ·
Los mantenedores suelen responder en 2 días
-
refresh_from_db silently ignores fields supplied as an iteratorPosiblemente ocupada @IlyaKhalafi la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 35/100
tortoise/tortoise-orm#2341 ·
Los mantenedores suelen responder en 2 días
-
Renamed fields break dict(model) and default values_listPosiblemente ocupada @IlyaKhalafi la tomó hoy. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 25/100
tortoise/tortoise-orm#2337 ·
Los mantenedores suelen responder en 2 días
-
Reverse relation filters use attribute names for SQL columnsPosiblemente ocupada @IlyaKhalafi la tomó hoy. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
tortoise/tortoise-orm#2336 ·
Los mantenedores suelen responder en 2 días
Todos los issues de tortoise/tortoise-orm
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
huggingface/sentence-transformers#4186 ·
Los mantenedores suelen responder en 5 días
-
documentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
QuantEcon/QuantEcon.py#988 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
fabriziosalmi/certmate#1247 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
documentation good first issue
Dificultad 2/5 Medio día Aptitud para principiantes 72/100
sujithputta02/Esapay#13 ·