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