From 27ee608b5557c3cd18aab6a61f854a0f6c18f3df Mon Sep 17 00:00:00 2001 From: Colin Wood Date: Tue, 1 Jul 2014 16:42:25 -0400 Subject: [PATCH] Fixed #22940 -- Added missing string iterpolation parameters in migrations.writer error. Forwardport of f5740af868 from stable/1.7.x --- AUTHORS | 1 + django/db/migrations/writer.py | 2 +- tests/migrations/test_writer.py | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 2fb754b543..3f2e7030fd 100644 --- a/AUTHORS +++ b/AUTHORS @@ -684,6 +684,7 @@ answer newbie questions, and generally made Django that much better: Jakub Wiśniowski Maciej Wiśniowski wojtek + Colin Wood Marcin Wróbel Jason Yan Lars Yencken diff --git a/django/db/migrations/writer.py b/django/db/migrations/writer.py index 71f81e9e2d..68f3eb50ce 100644 --- a/django/db/migrations/writer.py +++ b/django/db/migrations/writer.py @@ -319,7 +319,7 @@ class MigrationWriter(object): "and used in the same class body). Please move the " "function into the main module body to use migrations.\n" "For more information, see https://docs.djangoproject.com/en/1.7/topics/migrations/#serializing-values" - ) + % (value.__name__, module_name)) return "%s.%s" % (module_name, value.__name__), set(["import %s" % module_name]) # Classes elif isinstance(value, type): diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index 8f8437faf9..cce077566a 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -167,6 +167,19 @@ class WriterTests(TestCase): with self.assertRaises(ValueError): self.serialize_round_trip(TestModel2.thing) + def test_serialize_local_function_reference_message(self): + """ + Make sure user is seeing which module/function is the issue + """ + class TestModel2(object): + def upload_to(self): + return "somewhere dynamic" + thing = models.FileField(upload_to=upload_to) + + with six.assertRaisesRegex(self, ValueError, + '^Could not find function upload_to in migrations.test_writer'): + self.serialize_round_trip(TestModel2.thing) + def test_simple_migration(self): """ Tests serializing a simple migration.