summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClifford Gama <cliffygamy@gmail.com>2025-06-12 09:35:07 +0200
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-06-16 10:40:29 +0200
commit104cbfd44b9eff010daf0ef0e1ce434385855b13 (patch)
treef0d975b1a8e065cb5d0d5c425ba42cd1763e5711 /tests
parent12c1557060fc94fe5e1fbddc4578a4e29d38f77c (diff)
Fixed #36453 -- Made When.condition resolve with for_save=False.
Value(None, JSONField()) when used in When.condition incorrectly resolved with for_save=True, resulting in the value being serialized as SQL NULL instead of JSON null. Regression in c1fa3fdd040718356e5a3b9a0fe699d73f47a940. Thanks to Thomas McKay for the report, and to David Sanders and Simon Charettes for the review. Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/expressions/tests.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py
index 1fb4e2f34d..5f61f65ac0 100644
--- a/tests/expressions/tests.py
+++ b/tests/expressions/tests.py
@@ -29,6 +29,7 @@ from django.db.models import (
FloatField,
Func,
IntegerField,
+ JSONField,
Max,
Min,
Model,
@@ -83,6 +84,7 @@ from .models import (
Company,
Employee,
Experiment,
+ JSONFieldModel,
Manager,
Number,
RemoteEmployee,
@@ -367,6 +369,21 @@ class BasicExpressionsTests(TestCase):
Number.objects.all(), [None, None], lambda n: n.float, ordered=False
)
+ @skipUnlessDBFeature("supports_json_field")
+ def test_update_jsonfield_case_when_key_is_null(self):
+ obj = JSONFieldModel.objects.create(data={"key": None})
+ updated = JSONFieldModel.objects.update(
+ data=Case(
+ When(
+ data__key=Value(None, JSONField()),
+ then=Value({"key": "something"}, JSONField()),
+ ),
+ )
+ )
+ self.assertEqual(updated, 1)
+ obj.refresh_from_db()
+ self.assertEqual(obj.data, {"key": "something"})
+
def test_filter_with_join(self):
# F Expressions can also span joins
Company.objects.update(point_of_contact=F("ceo"))