mirror of
https://github.com/django/django.git
synced 2025-11-25 21:22:14 +00:00
Fixed #34697 -- Fixed non-deterministic order of dependencies and sets/frozensets in migrations.
Co-authored-by: Dakota Hawkins <dakotahawkins@gmail.com>
This commit is contained in:
parent
4afaeb14c2
commit
02966a30dd
4 changed files with 43 additions and 3 deletions
|
|
@ -768,12 +768,17 @@ class WriterTests(SimpleTestCase):
|
|||
def test_serialize_frozensets(self):
|
||||
self.assertSerializedEqual(frozenset())
|
||||
self.assertSerializedEqual(frozenset("let it go"))
|
||||
self.assertSerializedResultEqual(
|
||||
frozenset("cba"), ("frozenset(['a', 'b', 'c'])", set())
|
||||
)
|
||||
|
||||
def test_serialize_set(self):
|
||||
self.assertSerializedEqual(set())
|
||||
self.assertSerializedResultEqual(set(), ("set()", set()))
|
||||
self.assertSerializedEqual({"a"})
|
||||
self.assertSerializedResultEqual({"a"}, ("{'a'}", set()))
|
||||
self.assertSerializedEqual({"c", "b", "a"})
|
||||
self.assertSerializedResultEqual({"c", "b", "a"}, ("{'a', 'b', 'c'}", set()))
|
||||
|
||||
def test_serialize_timedelta(self):
|
||||
self.assertSerializedEqual(datetime.timedelta())
|
||||
|
|
@ -891,6 +896,33 @@ class WriterTests(SimpleTestCase):
|
|||
result["custom_migration_operations"].more_operations.TestOperation,
|
||||
)
|
||||
|
||||
def test_sorted_dependencies(self):
|
||||
migration = type(
|
||||
"Migration",
|
||||
(migrations.Migration,),
|
||||
{
|
||||
"operations": [
|
||||
migrations.AddField("mymodel", "myfield", models.IntegerField()),
|
||||
],
|
||||
"dependencies": [
|
||||
("testapp10", "0005_fifth"),
|
||||
("testapp02", "0005_third"),
|
||||
("testapp02", "0004_sixth"),
|
||||
("testapp01", "0001_initial"),
|
||||
],
|
||||
},
|
||||
)
|
||||
output = MigrationWriter(migration, include_header=False).as_string()
|
||||
self.assertIn(
|
||||
" dependencies = [\n"
|
||||
" ('testapp01', '0001_initial'),\n"
|
||||
" ('testapp02', '0004_sixth'),\n"
|
||||
" ('testapp02', '0005_third'),\n"
|
||||
" ('testapp10', '0005_fifth'),\n"
|
||||
" ]",
|
||||
output,
|
||||
)
|
||||
|
||||
def test_sorted_imports(self):
|
||||
"""
|
||||
#24155 - Tests ordering of imports.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue