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)
|
value = force_text(value)
|
||||||
|
|
||||||
# Sequences
|
# Sequences
|
||||||
if isinstance(value, (list, set, tuple)):
|
if isinstance(value, (frozenset, list, set, tuple)):
|
||||||
imports = set()
|
imports = set()
|
||||||
strings = []
|
strings = []
|
||||||
for item in value:
|
for item in value:
|
||||||
|
@ -312,6 +312,8 @@ class MigrationWriter(object):
|
||||||
if isinstance(value, set):
|
if isinstance(value, set):
|
||||||
# Don't use the literal "{%s}" as it doesn't support empty set
|
# Don't use the literal "{%s}" as it doesn't support empty set
|
||||||
format = "set([%s])"
|
format = "set([%s])"
|
||||||
|
elif isinstance(value, frozenset):
|
||||||
|
format = "frozenset([%s])"
|
||||||
elif isinstance(value, tuple):
|
elif isinstance(value, tuple):
|
||||||
# When len(value)==0, the empty tuple should be serialized as
|
# When len(value)==0, the empty tuple should be serialized as
|
||||||
# "()", not "(,)" because (,) is invalid Python syntax.
|
# "()", not "(,)" because (,) is invalid Python syntax.
|
||||||
|
|
|
@ -347,6 +347,10 @@ class WriterTests(TestCase):
|
||||||
self.assertSerializedEqual(FoodManager('a', 'b'))
|
self.assertSerializedEqual(FoodManager('a', 'b'))
|
||||||
self.assertSerializedEqual(FoodManager('x', 'y', c=3, d=4))
|
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):
|
def test_simple_migration(self):
|
||||||
"""
|
"""
|
||||||
Tests serializing a simple migration.
|
Tests serializing a simple migration.
|
||||||
|
|
Loading…
Reference in New Issue