Skip to content

Commit

Permalink
Revert "Use topological sort for migration operation dependency resol…
Browse files Browse the repository at this point in the history
…ution"

This commit broke the tests on Python 3.

This reverts commit 13d613f.
  • Loading branch information
timgraham committed Nov 15, 2014
1 parent f59fd15 commit 83d104d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 53 deletions.
1 change: 0 additions & 1 deletion AUTHORS
Expand Up @@ -378,7 +378,6 @@ answer newbie questions, and generally made Django that much better:
Kevin McConnell <kevin.mcconnell@gmail.com>
Kieran Holland <http://www.kieranholland.com>
kilian <kilian.cavalotti@lip6.fr>
Klaas van Schelven <klaas@vanschelven.com>
knox <christobzr@gmail.com>
konrad@gwu.edu
Kowito Charoenratchatabhan <kowito@felspar.com>
Expand Down
37 changes: 22 additions & 15 deletions django/db/migrations/autodetector.py
Expand Up @@ -14,8 +14,6 @@
from django.db.migrations.optimizer import MigrationOptimizer
from django.db.migrations.operations.models import AlterModelOptions

from .topological_sort import stable_topological_sort


class MigrationAutodetector(object):
"""
Expand Down Expand Up @@ -193,19 +191,28 @@ def _detect_changes(self, convert_apps=None, graph=None):
# isn't bad, but we need to pull a few things around so FKs work nicely
# inside the same app
for app_label, ops in sorted(self.generated_operations.items()):

# construct a dependency-graph for in-app dependencies
dependency_graph = dict((op, set()) for op in ops)
for op in ops:
for dep in op._auto_deps:
if dep[0] == app_label:
for op2 in ops:
if self.check_dependency(op2, dep):
dependency_graph[op].add(op2)

# we use a stable sort for deterministic tests & general behavior
self.generated_operations[app_label] = stable_topological_sort(
ops, dependency_graph)
for i in range(10000):
found = False
for i, op in enumerate(ops):
for dep in op._auto_deps:
if dep[0] == app_label:
# Alright, there's a dependency on the same app.
for j, op2 in enumerate(ops):
if j > i and self.check_dependency(op2, dep):
# shift the operation from position i after
# the operation at position j
ops = ops[:i] + ops[i + 1:j + 1] + [op] + ops[j + 1:]
found = True
break
if found:
break
if found:
break
if not found:
break
else:
raise ValueError("Infinite loop caught in operation dependency resolution")
self.generated_operations[app_label] = ops

# Now, we need to chop the lists of operations up into migrations with
# dependencies on each other.
Expand Down
34 changes: 0 additions & 34 deletions django/db/migrations/topological_sort.py

This file was deleted.

6 changes: 3 additions & 3 deletions tests/migrations/test_autodetector.py
Expand Up @@ -1107,12 +1107,12 @@ def test_m2m_w_through_multistep_remove(self):
# Right number of migrations?
self.assertNumberMigrations(changes, "testapp", 1)
# Right actions in right order?
self.assertOperationTypes(changes, "testapp", 0, ["RemoveField", "RemoveField", "RemoveField", "DeleteModel", "DeleteModel"])
self.assertOperationTypes(changes, "testapp", 0, ["RemoveField", "RemoveField", "DeleteModel", "RemoveField", "DeleteModel"])
# Actions touching the right stuff?
self.assertOperationAttributes(changes, "testapp", 0, 0, name="publishers")
self.assertOperationAttributes(changes, "testapp", 0, 1, name="author")
self.assertOperationAttributes(changes, "testapp", 0, 2, name="publisher")
self.assertOperationAttributes(changes, "testapp", 0, 3, name="Author")
self.assertOperationAttributes(changes, "testapp", 0, 2, name="Author")
self.assertOperationAttributes(changes, "testapp", 0, 3, name="publisher")
self.assertOperationAttributes(changes, "testapp", 0, 4, name="Contract")

def test_non_circular_foreignkey_dependency_removal(self):
Expand Down

0 comments on commit 83d104d

Please sign in to comment.