Opened 3 months ago
Last modified 2 months ago
#36445 closed Bug
Value(None, output_field=JSONField()) incorrectly saves as SQL NULL in bulk_update() — at Version 2
Reported by: | Clifford Gama | Owned by: | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Simon Charette, Thomas | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
When using bulk_update()
with a Value(None, output_field=JSONField())
expression, the value is incorrectly saved as a SQL NULL
rather than a JSON null
. This behavior was temporarily fixed in 00c690efbc0b10f67924687f24a7b30397bf47d9 due to incomplete for_save
propagation during expression resolution (bug in #36419), but reappears after the proper restoration of for_save
handling in #36419.
-
tests/queries/test_bulk_update.py
diff --git a/tests/queries/test_bulk_update.py b/tests/queries/test_bulk_update.py index 480fac6784..6c553421cb 100644
a b from math import ceil 3 3 4 4 from django.core.exceptions import FieldDoesNotExist 5 5 from django.db import connection 6 from django.db.models import F 6 from django.db.models import F, Value, JSONField 7 7 from django.db.models.functions import Coalesce, Lower 8 8 from django.db.utils import IntegrityError 9 9 from django.test import TestCase, override_settings, skipUnlessDBFeature … … class BulkUpdateTests(TestCase): 315 315 sql_null_qs = JSONFieldNullable.objects.filter(json_field__isnull=True) 316 316 self.assertSequenceEqual(sql_null_qs, [obj]) 317 317 318 @skipUnlessDBFeature("supports_json_field") 319 def test_json_field_json_null_value(self): 320 obj = JSONFieldNullable.objects.create(json_field={}) 321 obj.json_field = Value(None, output_field=JSONField()) 322 JSONFieldNullable.objects.bulk_update([obj], fields=["json_field"]) 323 obj.refresh_from_db() 324 json_null_qs = JSONFieldNullable.objects.filter(json_field=None) 325 self.assertSequenceEqual(json_null_qs, [obj]) 326 318 327 def test_nullable_fk_after_related_save(self): 319 328 parent = RelatedObject.objects.create() 320 329 child = SingleObject()
Change History (2)
comment:1 by , 3 months ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 3 months ago
Description: | modified (diff) |
---|
Note:
See TracTickets
for help on using tickets.
Thank you for the ticket