From ff9e1161984f43f34f9ecff5ee80959016447cf3 Mon Sep 17 00:00:00 2001 From: Loic Bistuer Date: Sun, 1 Sep 2013 02:11:37 +0700 Subject: [PATCH] Fixed #21008 -- Made MigrationWriter handle Promise objects. --- django/db/migrations/writer.py | 5 +++++ tests/migrations/test_writer.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/django/db/migrations/writer.py b/django/db/migrations/writer.py index 75a44a8b95..e23f15dd77 100644 --- a/django/db/migrations/writer.py +++ b/django/db/migrations/writer.py @@ -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() diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index 05757bb238..ff6fc47737 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -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)