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):
|
326 | 326 | """ |
327 | 327 | if not prepared: |
328 | 328 | value = self.get_prep_lookup(lookup_type, value) |
| 329 | prepared = True |
329 | 330 | if hasattr(value, 'get_compiler'): |
330 | 331 | value = value.get_compiler(connection=connection) |
331 | 332 | if hasattr(value, 'as_sql') or hasattr(value, '_as_sql'): |
diff --git a/tests/regressiontests/model_fields/models.py b/tests/regressiontests/model_fields/models.py
index 4dcfb17..caa36c7 100644
a
|
b
|
if Image:
|
163 | 163 | headshot = TestImageField(blank=True, null=True, |
164 | 164 | storage=temp_storage, upload_to='tests', |
165 | 165 | height_field='headshot_height', |
166 | | width_field='headshot_width') |
167 | | |
168 | | ############################################################################### |
| 166 | width_field='headshot_width') |
| 167 | No newline at end of file |
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):
|
365 | 365 | field = d._meta.get_field('myfile') |
366 | 366 | field.save_form_data(d, 'else.txt') |
367 | 367 | self.assertEqual(d.myfile, 'else.txt') |
| 368 | |
| 369 | |
| 370 | class 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) |