Fixed #25186 -- Improved migration's serialization of builtins on Python 2.
This commit is contained in:
parent
5d60d2b457
commit
b1e552debf
|
@ -472,6 +472,9 @@ class MigrationWriter(object):
|
|||
"For more information, see "
|
||||
"https://docs.djangoproject.com/en/%s/topics/migrations/#serializing-values"
|
||||
% (value.__name__, module_name, get_docs_version()))
|
||||
# Needed on Python 2 only
|
||||
if module_name == '__builtin__':
|
||||
return value.__name__, set()
|
||||
return "%s.%s" % (module_name, value.__name__), {"import %s" % module_name}
|
||||
# Other iterables
|
||||
elif isinstance(value, collections.Iterable):
|
||||
|
|
|
@ -359,6 +359,11 @@ class WriterTests(SimpleTestCase):
|
|||
self.assertSerializedEqual(one_item_tuple)
|
||||
self.assertSerializedEqual(many_items_tuple)
|
||||
|
||||
def test_serialize_builtins(self):
|
||||
string, imports = MigrationWriter.serialize(range)
|
||||
self.assertEqual(string, 'range')
|
||||
self.assertEqual(imports, set())
|
||||
|
||||
@unittest.skipUnless(six.PY2, "Only applies on Python 2")
|
||||
def test_serialize_direct_function_reference(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue