Ticket #14786: ticket14786.diff

File ticket14786.diff, 2.4 KB (added by Łukasz Rekucki, 13 years ago)
  • django/db/models/fields/__init__.py

    diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
    index 42b727d..d8b0642 100644
    a b class Field(object):  
    326326        """
    327327        if not prepared:
    328328            value = self.get_prep_lookup(lookup_type, value)
     329            prepared = True
    329330        if hasattr(value, 'get_compiler'):
    330331            value = value.get_compiler(connection=connection)
    331332        if hasattr(value, 'as_sql') or hasattr(value, '_as_sql'):
  • tests/regressiontests/model_fields/models.py

    diff --git a/tests/regressiontests/model_fields/models.py b/tests/regressiontests/model_fields/models.py
    index 4dcfb17..caa36c7 100644
    a b if Image:  
    163163        headshot = TestImageField(blank=True, null=True,
    164164                                  storage=temp_storage, upload_to='tests',
    165165                                  height_field='headshot_height',
    166                                   width_field='headshot_width')
    167 
    168 ###############################################################################
     166                                  width_field='headshot_width')
     167 No newline at end of file
  • tests/regressiontests/model_fields/tests.py

    diff --git a/tests/regressiontests/model_fields/tests.py b/tests/regressiontests/model_fields/tests.py
    index 8fe67fb..7ed0a3a 100644
    a b class FileFieldTests(unittest.TestCase):  
    365365        field = d._meta.get_field('myfile')
    366366        field.save_form_data(d, 'else.txt')
    367367        self.assertEqual(d.myfile, 'else.txt')
     368
     369
     370class CustomFieldTests(unittest.TestCase):
     371
     372    def test_14786(self):
     373        """
     374        Test that field values are not prepared twice.
     375        """
     376        prepare_count = [0]
     377        class NoopField(models.TextField):
     378            def get_prep_value(self, value):
     379                prepare_count[0] += 1
     380                return super(NoopField, self).get_prep_value(value).encode('base64')
     381
     382        # Regression test for #14786. When get_db_prep_lookup is called with
     383        # prepared = False, the value is passed through get_prep_value twice.
     384        from django.db import connection
     385        field = NoopField()
     386        field.get_db_prep_lookup('exact', 'TEST', connection=connection, prepared=False)
     387        self.assertEqual(prepare_count[0], 1)
Back to Top