diff options
| author | Tim Graham <timograham@gmail.com> | 2013-08-29 11:09:58 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-08-29 11:13:34 -0400 |
| commit | f19a3669b87641d7882491c3590d3c1c79756197 (patch) | |
| tree | d7b3e9ccde0261fc2b5957d84459da3af74d8229 | |
| parent | af953c45cc56df28d02675e196eca1b54ce28a43 (diff) | |
Fixed #14786 -- Fixed get_db_prep_lookup calling get_prep_value twice if prepared is False.
Thanks homm for the report and Aramgutang and lrekucki for work on
the patch.
| -rw-r--r-- | django/db/models/fields/__init__.py | 1 | ||||
| -rw-r--r-- | tests/model_fields/tests.py | 18 |
2 files changed, 19 insertions, 0 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 4135c60ad3..a6b37bcda6 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -499,6 +499,7 @@ class Field(object): """ if not prepared: value = self.get_prep_lookup(lookup_type, value) + prepared = True if hasattr(value, 'get_compiler'): value = value.get_compiler(connection=connection) if hasattr(value, 'as_sql') or hasattr(value, '_as_sql'): diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py index 429337f31c..0d327d6ae6 100644 --- a/tests/model_fields/tests.py +++ b/tests/model_fields/tests.py @@ -663,3 +663,21 @@ class PromiseTest(test.TestCase): self.assertIsInstance( URLField().get_prep_value(lazy_func()), six.text_type) + + +class CustomFieldTests(unittest.TestCase): + + def test_14786(self): + """ + Regression test for #14786 -- Test that field values are not prepared + twice in get_db_prep_lookup(). + """ + prepare_count = [0] + class NoopField(models.TextField): + def get_prep_value(self, value): + prepare_count[0] += 1 + return super(NoopField, self).get_prep_value(value) + + field = NoopField() + field.get_db_prep_lookup('exact', 'TEST', connection=connection, prepared=False) + self.assertEqual(prepare_count[0], 1) |
