Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.
  • Loading branch information...
commit f19a3669b87641d7882491c3590d3c1c79756197 1 parent af953c4
Tim Graham authored
1  django/db/models/fields/__init__.py
@@ -499,6 +499,7 @@ def get_db_prep_lookup(self, lookup_type, value, connection,
499 499
         """
500 500
         if not prepared:
501 501
             value = self.get_prep_lookup(lookup_type, value)
  502
+            prepared = True
502 503
         if hasattr(value, 'get_compiler'):
503 504
             value = value.get_compiler(connection=connection)
504 505
         if hasattr(value, 'as_sql') or hasattr(value, '_as_sql'):
18  tests/model_fields/tests.py
@@ -663,3 +663,21 @@ def test_URLField(self):
663 663
         self.assertIsInstance(
664 664
             URLField().get_prep_value(lazy_func()),
665 665
             six.text_type)
  666
+
  667
+
  668
+class CustomFieldTests(unittest.TestCase):
  669
+
  670
+    def test_14786(self):
  671
+        """
  672
+        Regression test for #14786 -- Test that field values are not prepared
  673
+        twice in get_db_prep_lookup().
  674
+        """
  675
+        prepare_count = [0]
  676
+        class NoopField(models.TextField):
  677
+            def get_prep_value(self, value):
  678
+                prepare_count[0] += 1
  679
+                return super(NoopField, self).get_prep_value(value)
  680
+
  681
+        field = NoopField()
  682
+        field.get_db_prep_lookup('exact', 'TEST', connection=connection, prepared=False)
  683
+        self.assertEqual(prepare_count[0], 1)

0 notes on commit f19a366

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