mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #34539 -- Restored get_prep_value() call when adapting JSONFields.
Regression in 5c23d9f0c3.
This commit is contained in:
committed by
Mariusz Felisiak
parent
7414704e88
commit
0ec60661e6
@@ -103,6 +103,29 @@ class TestMethods(SimpleTestCase):
|
||||
with self.assertRaisesMessage(TypeError, msg):
|
||||
KeyTransformTextLookupMixin(transform)
|
||||
|
||||
def test_get_prep_value(self):
|
||||
class JSONFieldGetPrepValue(models.JSONField):
|
||||
def get_prep_value(self, value):
|
||||
if value is True:
|
||||
return {"value": True}
|
||||
return value
|
||||
|
||||
def noop_adapt_json_value(value, encoder):
|
||||
return value
|
||||
|
||||
field = JSONFieldGetPrepValue()
|
||||
with mock.patch.object(
|
||||
connection.ops, "adapt_json_value", noop_adapt_json_value
|
||||
):
|
||||
self.assertEqual(
|
||||
field.get_db_prep_value(True, connection, prepared=False),
|
||||
{"value": True},
|
||||
)
|
||||
self.assertIs(
|
||||
field.get_db_prep_value(True, connection, prepared=True), True
|
||||
)
|
||||
self.assertEqual(field.get_db_prep_value(1, connection, prepared=False), 1)
|
||||
|
||||
|
||||
class TestValidation(SimpleTestCase):
|
||||
def test_invalid_encoder(self):
|
||||
|
||||
Reference in New Issue
Block a user