mirror of https://github.com/django/django.git
Refs #27914 -- Fixed serialization of nested enum.Enum classes in migrations.
This commit is contained in:
parent
d3030deaaa
commit
6452112640
|
@ -121,7 +121,7 @@ class EnumSerializer(BaseSerializer):
|
||||||
enum_class = self.value.__class__
|
enum_class = self.value.__class__
|
||||||
module = enum_class.__module__
|
module = enum_class.__module__
|
||||||
return (
|
return (
|
||||||
'%s.%s[%r]' % (module, enum_class.__name__, self.value.name),
|
'%s.%s[%r]' % (module, enum_class.__qualname__, self.value.name),
|
||||||
{'import %s' % module},
|
{'import %s' % module},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -184,6 +184,9 @@ class WriterTests(SimpleTestCase):
|
||||||
"""
|
"""
|
||||||
Tests the migration writer (makes migration files from Migration instances)
|
Tests the migration writer (makes migration files from Migration instances)
|
||||||
"""
|
"""
|
||||||
|
class NestedEnum(enum.IntEnum):
|
||||||
|
A = 1
|
||||||
|
B = 2
|
||||||
|
|
||||||
def safe_exec(self, string, value=None):
|
def safe_exec(self, string, value=None):
|
||||||
d = {}
|
d = {}
|
||||||
|
@ -289,6 +292,14 @@ class WriterTests(SimpleTestCase):
|
||||||
IntEnum.B,
|
IntEnum.B,
|
||||||
("migrations.test_writer.IntEnum['B']", {'import migrations.test_writer'})
|
("migrations.test_writer.IntEnum['B']", {'import migrations.test_writer'})
|
||||||
)
|
)
|
||||||
|
self.assertSerializedResultEqual(
|
||||||
|
self.NestedEnum.A,
|
||||||
|
(
|
||||||
|
"migrations.test_writer.WriterTests.NestedEnum['A']",
|
||||||
|
{'import migrations.test_writer'},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
self.assertSerializedEqual(self.NestedEnum.A)
|
||||||
|
|
||||||
field = models.CharField(default=TextEnum.B, choices=[(m.value, m) for m in TextEnum])
|
field = models.CharField(default=TextEnum.B, choices=[(m.value, m) for m in TextEnum])
|
||||||
string = MigrationWriter.serialize(field)[0]
|
string = MigrationWriter.serialize(field)[0]
|
||||||
|
|
Loading…
Reference in New Issue