mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #23844 -- Used topological sort for migration operation dependency resolution.
This removes the concept of equality between operations to guarantee
compatilibity with Python 3.
Python 3 requires equality to result in identical object hashes. It's
impossible to implement a unique hash that preserves equality as
operations such as field creation depend on being able to accept
arbitrary dicts that cannot be hashed reliably.
Thanks Klaas van Schelven for the original patch in
13d613f800.
This commit is contained in:
committed by
Tim Graham
parent
53908c1f93
commit
21e21c7bc2
@@ -20,43 +20,14 @@ class OptimizerTests(TestCase):
|
||||
|
||||
def assertOptimizesTo(self, operations, expected, exact=None, less_than=None):
|
||||
result, iterations = self.optimize(operations)
|
||||
result = [repr(f.deconstruct()) for f in result]
|
||||
expected = [repr(f.deconstruct()) for f in expected]
|
||||
self.assertEqual(expected, result)
|
||||
if exact is not None and iterations != exact:
|
||||
raise self.failureException("Optimization did not take exactly %s iterations (it took %s)" % (exact, iterations))
|
||||
if less_than is not None and iterations >= less_than:
|
||||
raise self.failureException("Optimization did not take less than %s iterations (it took %s)" % (less_than, iterations))
|
||||
|
||||
def test_operation_equality(self):
|
||||
"""
|
||||
Tests the equality operator on lists of operations.
|
||||
If this is broken, then the optimizer will get stuck in an
|
||||
infinite loop, so it's kind of important.
|
||||
"""
|
||||
self.assertEqual(
|
||||
[migrations.DeleteModel("Test")],
|
||||
[migrations.DeleteModel("Test")],
|
||||
)
|
||||
self.assertEqual(
|
||||
[migrations.CreateModel("Test", [("name", models.CharField(max_length=255))])],
|
||||
[migrations.CreateModel("Test", [("name", models.CharField(max_length=255))])],
|
||||
)
|
||||
self.assertNotEqual(
|
||||
[migrations.CreateModel("Test", [("name", models.CharField(max_length=255))])],
|
||||
[migrations.CreateModel("Test", [("name", models.CharField(max_length=100))])],
|
||||
)
|
||||
self.assertEqual(
|
||||
[migrations.AddField("Test", "name", models.CharField(max_length=255))],
|
||||
[migrations.AddField("Test", "name", models.CharField(max_length=255))],
|
||||
)
|
||||
self.assertNotEqual(
|
||||
[migrations.AddField("Test", "name", models.CharField(max_length=255))],
|
||||
[migrations.AddField("Test", "name", models.CharField(max_length=100))],
|
||||
)
|
||||
self.assertNotEqual(
|
||||
[migrations.AddField("Test", "name", models.CharField(max_length=255))],
|
||||
[migrations.AlterField("Test", "name", models.CharField(max_length=255))],
|
||||
)
|
||||
|
||||
def test_single(self):
|
||||
"""
|
||||
Tests that the optimizer does nothing on a single operation,
|
||||
@@ -331,7 +302,7 @@ class OptimizerTests(TestCase):
|
||||
migrations.AlterField("Foo", "age", models.FloatField(default=2.4)),
|
||||
],
|
||||
[
|
||||
migrations.AddField("Foo", "age", models.FloatField(default=2.4)),
|
||||
migrations.AddField("Foo", name="age", field=models.FloatField(default=2.4)),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user