Ticket #14786: 14786_fix_with_tests.diff
File 14786_fix_with_tests.diff, 2.8 KB (added by , 14 years ago) |
---|
-
django/db/models/fields/__init__.py
304 304 "Returns field's value prepared for database lookup." 305 305 if not prepared: 306 306 value = self.get_prep_lookup(lookup_type, value) 307 prepared = True 307 308 if hasattr(value, 'get_compiler'): 308 309 value = value.get_compiler(connection=connection) 309 310 if hasattr(value, 'as_sql') or hasattr(value, '_as_sql'): -
tests/regressiontests/model_fields/tests.py
8 8 from django.db.models.fields.files import FieldFile 9 9 from django.utils import unittest 10 10 11 from models import Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post, NullBooleanModel, BooleanModel, Document 11 from models import (Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post, 12 NullBooleanModel, BooleanModel, Document, Base64TextField) 12 13 13 14 # If PIL available, do these tests. 14 15 if Image: … … 348 349 field = d._meta.get_field('myfile') 349 350 field.save_form_data(d, 'else.txt') 350 351 self.assertEqual(d.myfile, 'else.txt') 352 353 class CustomFieldTests(unittest.TestCase): 354 def test_14786(self): 355 """ 356 Test that field values are not prepped twice. 357 """ 358 # Regression test for #14786. When get_db_prep_lookup is called with 359 # prepared = False, the value is passed through get_prep_value twice. 360 from django.db import connection 361 self.assertEqual( 362 Base64TextField().get_db_prep_lookup('exact', 363 'test', 364 connection=connection, 365 prepared=False), 366 ['dGVzdA==\n']) 367 -
tests/regressiontests/model_fields/models.py
158 158 width_field='headshot_width') 159 159 160 160 ############################################################################### 161 # Custom field 162 163 class Base64TextField(models.TextField): 164 def get_prep_value(self, value): 165 if value is None: 166 return value 167 return super(Base64TextField, self).get_prep_value(value).encode('base64') 168 169 170 ###############################################################################