Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Circular migration dependencies make forwards_plan/backwards_plan hang instead of raising

Abierto
#2,304 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

@moneebullah25 ya está trabajando en esto.

Desde el 9/10/2026.

  • #2306 de @moneebullah25 — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
Medio día
Aptitud para principiantes
68/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
databases

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):

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

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de tortoise/tortoise-orm

Todos los issues de tortoise/tortoise-orm

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.