mirror of
https://github.com/django/django.git
synced 2025-02-28 19:44:35 +00:00
[4.2.x] Fixed #34539 -- Restored get_prep_value() call when adapting JSONFields.
Regression in 5c23d9f0c32f166c81ecb6f3f01d5077a6084318. Backport of 0ec60661e61b153e6bcec64649b1b7f524eb3e18 from main
This commit is contained in:
parent
ddccecee91
commit
9c301814b0
1
AUTHORS
1
AUTHORS
@ -530,6 +530,7 @@ answer newbie questions, and generally made Django that much better:
|
|||||||
Julia Elman
|
Julia Elman
|
||||||
Julia Matsieva <julia.matsieva@gmail.com>
|
Julia Matsieva <julia.matsieva@gmail.com>
|
||||||
Julian Bez
|
Julian Bez
|
||||||
|
Julie Rymer <rymerjulie.pro@gmail.com>
|
||||||
Julien Phalip <jphalip@gmail.com>
|
Julien Phalip <jphalip@gmail.com>
|
||||||
Junyoung Choi <cupjoo@gmail.com>
|
Junyoung Choi <cupjoo@gmail.com>
|
||||||
junzhang.jn@gmail.com
|
junzhang.jn@gmail.com
|
||||||
|
@ -99,6 +99,8 @@ class JSONField(CheckFieldDefaultMixin, Field):
|
|||||||
return "JSONField"
|
return "JSONField"
|
||||||
|
|
||||||
def get_db_prep_value(self, value, connection, prepared=False):
|
def get_db_prep_value(self, value, connection, prepared=False):
|
||||||
|
if not prepared:
|
||||||
|
value = self.get_prep_value(value)
|
||||||
# RemovedInDjango51Warning: When the deprecation ends, replace with:
|
# RemovedInDjango51Warning: When the deprecation ends, replace with:
|
||||||
# if (
|
# if (
|
||||||
# isinstance(value, expressions.Value)
|
# isinstance(value, expressions.Value)
|
||||||
|
@ -12,3 +12,6 @@ Bugfixes
|
|||||||
* Fixed a regression in Django 4.2 that caused an unnecessary
|
* Fixed a regression in Django 4.2 that caused an unnecessary
|
||||||
``DBMS_LOB.SUBSTR()`` wrapping in the ``__isnull`` and ``__exact=None``
|
``DBMS_LOB.SUBSTR()`` wrapping in the ``__isnull`` and ``__exact=None``
|
||||||
lookups for ``TextField()``/``BinaryField()`` on Oracle (:ticket:`34544`).
|
lookups for ``TextField()``/``BinaryField()`` on Oracle (:ticket:`34544`).
|
||||||
|
|
||||||
|
* Restored, following a regression in Django 4.2, ``get_prep_value()`` call in
|
||||||
|
``JSONField`` subclasses (:ticket:`34539`).
|
||||||
|
@ -103,6 +103,29 @@ class TestMethods(SimpleTestCase):
|
|||||||
with self.assertRaisesMessage(TypeError, msg):
|
with self.assertRaisesMessage(TypeError, msg):
|
||||||
KeyTransformTextLookupMixin(transform)
|
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):
|
class TestValidation(SimpleTestCase):
|
||||||
def test_invalid_encoder(self):
|
def test_invalid_encoder(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user