mirror of https://github.com/django/django.git
Fixed #24521 -- Added support for serializing frozensets in migrations.
This commit is contained in:
parent
00e667728b
commit
1aadade373
|
@ -302,7 +302,7 @@ class MigrationWriter(object):
|
|||
value = force_text(value)
|
||||
|
||||
# Sequences
|
||||
if isinstance(value, (list, set, tuple)):
|
||||
if isinstance(value, (frozenset, list, set, tuple)):
|
||||
imports = set()
|
||||
strings = []
|
||||
for item in value:
|
||||
|
@ -312,6 +312,8 @@ class MigrationWriter(object):
|
|||
if isinstance(value, set):
|
||||
# Don't use the literal "{%s}" as it doesn't support empty set
|
||||
format = "set([%s])"
|
||||
elif isinstance(value, frozenset):
|
||||
format = "frozenset([%s])"
|
||||
elif isinstance(value, tuple):
|
||||
# When len(value)==0, the empty tuple should be serialized as
|
||||
# "()", not "(,)" because (,) is invalid Python syntax.
|
||||
|
|
|
@ -347,6 +347,10 @@ class WriterTests(TestCase):
|
|||
self.assertSerializedEqual(FoodManager('a', 'b'))
|
||||
self.assertSerializedEqual(FoodManager('x', 'y', c=3, d=4))
|
||||
|
||||
def test_serialize_frozensets(self):
|
||||
self.assertSerializedEqual(frozenset())
|
||||
self.assertSerializedEqual(frozenset("let it go"))
|
||||
|
||||
def test_simple_migration(self):
|
||||
"""
|
||||
Tests serializing a simple migration.
|
||||
|
|
Loading…
Reference in New Issue