Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.6.x] Fixed #14786 -- Fixed get_db_prep_lookup calling get_prep_val…

…ue twice if prepared is False.

Thanks homm for the report and Aramgutang and lrekucki for work on
the patch.

Backport of f19a366 from master
  • Loading branch information...
commit 10d15f79e5e2ca7b733e2bf1860e1778c3a712dc 1 parent ef12593
@timgraham timgraham authored
Showing with 19 additions and 0 deletions.
  1. +1 −0  django/db/models/fields/__init__.py
  2. +18 −0 tests/model_fields/tests.py
View
1  django/db/models/fields/__init__.py
@@ -385,6 +385,7 @@ def get_db_prep_lookup(self, lookup_type, value, connection,
"""
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'):
View
18 tests/model_fields/tests.py
@@ -494,3 +494,21 @@ def test_genericipaddressfield_formfield_protocol(self):
model_field = models.GenericIPAddressField(protocol='IPv6')
form_field = model_field.formfield()
self.assertRaises(ValidationError, form_field.clean, '127.0.0.1')
+
+
+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)
Please sign in to comment.
Something went wrong with that request. Please try again.