diff options
| author | Baptiste Mispelon <bmispelon@gmail.com> | 2015-03-23 15:38:25 +0100 |
|---|---|---|
| committer | Baptiste Mispelon <bmispelon@gmail.com> | 2015-03-23 15:38:25 +0100 |
| commit | 1aadade373336c3f534986cdcc0ba33714d85c8e (patch) | |
| tree | 9bde3c8cfd44ec2bc3e9c70ae0fe0bbd17e00f6e | |
| parent | 00e667728ba3ef1b5cb3de0e11c7648b89315a91 (diff) | |
Fixed #24521 -- Added support for serializing frozensets in migrations.
| -rw-r--r-- | django/db/migrations/writer.py | 4 | ||||
| -rw-r--r-- | tests/migrations/test_writer.py | 4 |
2 files changed, 7 insertions, 1 deletions
diff --git a/django/db/migrations/writer.py b/django/db/migrations/writer.py index 9067e7b605..f4f43ac930 100644 --- a/django/db/migrations/writer.py +++ b/django/db/migrations/writer.py @@ -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. diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index 28c68d871a..aa12c7c612 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -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. |
