1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Fixed #28152 -- Made migrations serialize sets as set literals rather than set().

This commit is contained in:
Jon Dufresne 2017-05-18 06:33:40 -07:00 committed by Tim Graham
parent 912ef7f49d
commit f599747fc8
8 changed files with 15 additions and 8 deletions

View File

@ -26,7 +26,7 @@ class Migration(migrations.Migration):
],
options={
'ordering': ('content_type__app_label', 'content_type__model', 'codename'),
'unique_together': set([('content_type', 'codename')]),
'unique_together': {('content_type', 'codename')},
'verbose_name': 'permission',
'verbose_name_plural': 'permissions',
},

View File

@ -29,6 +29,6 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name='contenttype',
unique_together=set([('app_label', 'model')]),
unique_together={('app_label', 'model')},
),
]

View File

@ -30,7 +30,7 @@ class Migration(migrations.Migration):
],
options={
'ordering': ('old_path',),
'unique_together': set([('site', 'old_path')]),
'unique_together': {('site', 'old_path')},
'db_table': 'django_redirect',
'verbose_name': 'redirect',
'verbose_name_plural': 'redirects',

View File

@ -244,8 +244,9 @@ class SequenceSerializer(BaseSequenceSerializer):
class SetSerializer(BaseSequenceSerializer):
def _format(self):
# Don't use the literal "{%s}" as it doesn't support empty set
return "set([%s])"
# Serialize as a set literal except when value is empty because {}
# is an empty dict.
return '{%s}' if self.value else 'set(%s)'
class SettingsReferenceSerializer(BaseSerializer):

View File

@ -30,6 +30,6 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name='author',
unique_together=set([('name', 'slug')]),
unique_together={('name', 'slug')},
),
]

View File

@ -25,6 +25,6 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name='author',
unique_together=set([('name', 'slug')]),
unique_together={('name', 'slug')},
),
]

View File

@ -25,6 +25,6 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name='author',
unique_together=set([('name', 'slug')]),
unique_together={('name', 'slug')},
),
]

View File

@ -505,6 +505,12 @@ class WriterTests(SimpleTestCase):
self.assertSerializedEqual(frozenset())
self.assertSerializedEqual(frozenset("let it go"))
def test_serialize_set(self):
self.assertSerializedEqual(set())
self.assertSerializedResultEqual(set(), ('set()', set()))
self.assertSerializedEqual({'a'})
self.assertSerializedResultEqual({'a'}, ("{'a'}", set()))
def test_serialize_timedelta(self):
self.assertSerializedEqual(datetime.timedelta())
self.assertSerializedEqual(datetime.timedelta(minutes=42))