mirror of https://github.com/django/django.git
Fixed #23560 -- Fixed MigrationWrite to handle builtin types without imports.
Thanks Tim Graham for the review.
This commit is contained in:
parent
f5c932ddec
commit
b23d47412c
|
@ -352,7 +352,10 @@ class MigrationWriter(object):
|
|||
return string, set(imports)
|
||||
if hasattr(value, "__module__"):
|
||||
module = value.__module__
|
||||
return "%s.%s" % (module, value.__name__), set(["import %s" % module])
|
||||
if module == six.moves.builtins.__name__:
|
||||
return value.__name__, set()
|
||||
else:
|
||||
return "%s.%s" % (module, value.__name__), set(["import %s" % module])
|
||||
# Other iterables
|
||||
elif isinstance(value, collections.Iterable):
|
||||
imports = set()
|
||||
|
|
|
@ -83,3 +83,6 @@ Bugfixes
|
|||
* Coerced the ``related_name`` model field option to unicode during migration
|
||||
generation to generate migrations that work with both Python 2 and 3
|
||||
(:ticket:`23455`).
|
||||
|
||||
* Fixed ``MigrationWriter`` to handle builtin types without imports
|
||||
(:ticket:`23560`).
|
||||
|
|
|
@ -81,6 +81,11 @@ class WriterTests(TestCase):
|
|||
self.assertSerializedEqual(set([2, 3, "eighty"]))
|
||||
self.assertSerializedEqual({"lalalala": ["yeah", "no", "maybe"]})
|
||||
self.assertSerializedEqual(_('Hello'))
|
||||
# Builtins
|
||||
self.assertSerializedEqual([list, tuple, dict, set])
|
||||
string, imports = MigrationWriter.serialize([list, tuple, dict, set])
|
||||
self.assertEqual(string, "[list, tuple, dict, set]")
|
||||
self.assertEqual(imports, set())
|
||||
# Functions
|
||||
with six.assertRaisesRegex(self, ValueError, 'Cannot serialize function: lambda'):
|
||||
self.assertSerializedEqual(lambda x: 42)
|
||||
|
|
Loading…
Reference in New Issue