1
0
mirror of https://github.com/django/django.git synced 2025-10-27 07:36:08 +00:00

Fixed #35167 -- Delegated to super() in JSONField.get_db_prep_save().

Avoids reports of bulk_update() sending Cast expressions
to JSONField.get_prep_value().

Co-authored-by: Simon Charette <charette.s@gmail.com>
This commit is contained in:
Jacob Walls
2025-02-16 21:35:12 -05:00
committed by Sarah Boyce
parent 9d22a7d8f0
commit 0bf412111b
3 changed files with 41 additions and 8 deletions

View File

@@ -40,7 +40,13 @@ from django.db.models.functions import Cast
from django.test import SimpleTestCase, TestCase, skipIfDBFeature, skipUnlessDBFeature
from django.test.utils import CaptureQueriesContext
from .models import CustomJSONDecoder, JSONModel, NullableJSONModel, RelatedJSONModel
from .models import (
CustomJSONDecoder,
CustomSerializationJSONModel,
JSONModel,
NullableJSONModel,
RelatedJSONModel,
)
@skipUnlessDBFeature("supports_json_field")
@@ -298,6 +304,17 @@ class TestSaveLoad(TestCase):
obj.refresh_from_db()
self.assertEqual(obj.value, value)
def test_bulk_update_custom_get_prep_value(self):
objs = CustomSerializationJSONModel.objects.bulk_create(
[CustomSerializationJSONModel(pk=1, json_field={"version": "1"})]
)
objs[0].json_field["version"] = "1-alpha"
CustomSerializationJSONModel.objects.bulk_update(objs, ["json_field"])
self.assertSequenceEqual(
CustomSerializationJSONModel.objects.values("json_field"),
[{"json_field": '{"version": "1-alpha"}'}],
)
@skipUnlessDBFeature("supports_json_field")
class TestQuerying(TestCase):