mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #27914 -- Fixed serialization of nested classes in migrations.
This commit is contained in:
parent
8008795a38
commit
29d8198841
@ -269,7 +269,7 @@ class TypeSerializer(BaseSerializer):
|
||||
if module == builtins.__name__:
|
||||
return self.value.__name__, set()
|
||||
else:
|
||||
return "%s.%s" % (module, self.value.__name__), {"import %s" % module}
|
||||
return "%s.%s" % (module, self.value.__qualname__), {"import %s" % module}
|
||||
|
||||
|
||||
class UUIDSerializer(BaseSerializer):
|
||||
|
@ -193,6 +193,10 @@ class WriterTests(SimpleTestCase):
|
||||
A = 1
|
||||
B = 2
|
||||
|
||||
class NestedChoices(models.TextChoices):
|
||||
X = 'X', 'X value'
|
||||
Y = 'Y', 'Y value'
|
||||
|
||||
def safe_exec(self, string, value=None):
|
||||
d = {}
|
||||
try:
|
||||
@ -388,6 +392,18 @@ class WriterTests(SimpleTestCase):
|
||||
"default=datetime.date(1969, 11, 19))"
|
||||
)
|
||||
|
||||
def test_serialize_nested_class(self):
|
||||
for nested_cls in [self.NestedEnum, self.NestedChoices]:
|
||||
cls_name = nested_cls.__name__
|
||||
with self.subTest(cls_name):
|
||||
self.assertSerializedResultEqual(
|
||||
nested_cls,
|
||||
(
|
||||
"migrations.test_writer.WriterTests.%s" % cls_name,
|
||||
{'import migrations.test_writer'},
|
||||
),
|
||||
)
|
||||
|
||||
def test_serialize_uuid(self):
|
||||
self.assertSerializedEqual(uuid.uuid1())
|
||||
self.assertSerializedEqual(uuid.uuid4())
|
||||
|
Loading…
Reference in New Issue
Block a user