Fixed #24521 -- Added support for serializing frozensets in migrations.

This commit is contained in:
Baptiste Mispelon 2015-03-23 15:38:25 +01:00
parent 00e667728b
commit 1aadade373
2 changed files with 7 additions and 1 deletions

View File

@ -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.

View File

@ -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.