Fixed #21008 -- Made MigrationWriter handle Promise objects.

This commit is contained in:
Loic Bistuer 2013-09-01 02:11:37 +07:00 committed by Tim Graham
parent 1c0c879be3
commit ff9e116198
2 changed files with 7 additions and 0 deletions

View File

@ -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()

View File

@ -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)