Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #21008 -- Made MigrationWriter handle Promise objects.

  • Loading branch information...
commit ff9e1161984f43f34f9ecff5ee80959016447cf3 1 parent 1c0c879
@loic loic authored timgraham committed
View
5 django/db/migrations/writer.py
@@ -7,6 +7,8 @@
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 @@ def serialize(cls, value):
# 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()
View
2  tests/migrations/test_writer.py
@@ -8,6 +8,7 @@
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 @@ def test_serialize(self):
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)
Please sign in to comment.
Something went wrong with that request. Please try again.