Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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
Tim Graham authored August 29, 2013
1  django/db/models/fields/__init__.py
@@ -385,6 +385,7 @@ def get_db_prep_lookup(self, lookup_type, value, connection,
385 385
         """
386 386
         if not prepared:
387 387
             value = self.get_prep_lookup(lookup_type, value)
  388
+            prepared = True
388 389
         if hasattr(value, 'get_compiler'):
389 390
             value = value.get_compiler(connection=connection)
390 391
         if hasattr(value, 'as_sql') or hasattr(value, '_as_sql'):
18  tests/model_fields/tests.py
@@ -494,3 +494,21 @@ def test_genericipaddressfield_formfield_protocol(self):
494 494
         model_field = models.GenericIPAddressField(protocol='IPv6')
495 495
         form_field = model_field.formfield()
496 496
         self.assertRaises(ValidationError, form_field.clean, '127.0.0.1')
  497
+
  498
+
  499
+class CustomFieldTests(unittest.TestCase):
  500
+
  501
+    def test_14786(self):
  502
+        """
  503
+        Regression test for #14786 -- Test that field values are not prepared
  504
+        twice in get_db_prep_lookup().
  505
+        """
  506
+        prepare_count = [0]
  507
+        class NoopField(models.TextField):
  508
+            def get_prep_value(self, value):
  509
+                prepare_count[0] += 1
  510
+                return super(NoopField, self).get_prep_value(value)
  511
+
  512
+        field = NoopField()
  513
+        field.get_db_prep_lookup('exact', 'TEST', connection=connection, prepared=False)
  514
+        self.assertEqual(prepare_count[0], 1)

0 notes on commit 10d15f7

Please sign in to comment.
Something went wrong with that request. Please try again.