mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #21008 -- Made MigrationWriter handle Promise objects.
This commit is contained in:
		| @@ -7,6 +7,8 @@ from django.utils import six | ||||
| from django.db import models | ||||
| from django.db.models.loading import cache | ||||
| from django.db.migrations.loader import MigrationLoader | ||||
| from django.utils.encoding import force_text | ||||
| from django.utils.functional import Promise | ||||
|  | ||||
|  | ||||
| class MigrationWriter(object): | ||||
| @@ -111,6 +113,9 @@ class MigrationWriter(object): | ||||
|         # Simple types | ||||
|         elif isinstance(value, six.integer_types + (float, six.binary_type, six.text_type, bool, type(None))): | ||||
|             return repr(value), set() | ||||
|         # Promise | ||||
|         elif isinstance(value, Promise): | ||||
|             return repr(force_text(value)), set() | ||||
|         # Django fields | ||||
|         elif isinstance(value, models.Field): | ||||
|             attr_name, path, args, kwargs = value.deconstruct() | ||||
|   | ||||
| @@ -8,6 +8,7 @@ from django.utils import six | ||||
| from django.test import TestCase | ||||
| from django.db.migrations.writer import MigrationWriter | ||||
| from django.db import models, migrations | ||||
| from django.utils.translation import ugettext_lazy as _ | ||||
|  | ||||
|  | ||||
| class WriterTests(TestCase): | ||||
| @@ -58,6 +59,7 @@ class WriterTests(TestCase): | ||||
|         self.assertSerializedEqual(["a", 2, True, None]) | ||||
|         self.assertSerializedEqual(set([2, 3, "eighty"])) | ||||
|         self.assertSerializedEqual({"lalalala": ["yeah", "no", "maybe"]}) | ||||
|         self.assertSerializedEqual(_('Hello')) | ||||
|         # Datetime stuff | ||||
|         self.assertSerializedEqual(datetime.datetime.utcnow()) | ||||
|         self.assertSerializedEqual(datetime.datetime.utcnow) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user