﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36440	bulk_update() on JSONField saves JSON null instead of SQL NULL	Adam Johnson	Adam Johnson	"I have a client project with a Django model that has a `JSONField` and a check constraint requiring the field to either contain SQL `NULL` or a JSON object (via a custom database function calling PostgreSQL's `jsonb_typeof`). Upgrading to Django 5.2 causes a `bulk_update()` query on that model to start failing with `IntegrityError`, because the JSON `null` is serialized instead (`'null'::json` in PostgreSQL syntax).

Like #36404 and #36405, this is another bug that bisects to e306687a3a5507d59365ba9bf545010e5fd4b2a8.

The issue:

1. `BaseExpression.resolve_expression()` no longer passes the `for_save` parameter through to source expressions.
2. When a source expression is a `Value`, `for_save` being `False` prevents it from calling `Field.get_db_prep_save()`: https://github.com/django/django/blob/f0a87895ffaf6532a22143b5e2e304c59b7958ae/django/db/models/expressions.py#L1170-L1173 .
3. `JSONField.get_db_prep_save()` has specific behaviour for `None`, ensuring it's returned as-is rather than wrapped as JSON: https://github.com/django/django/blob/main/django/db/models/fields/json.py#L110-L111
4. The missed call means `None` is wrapped as JSON null, which fails the model's check constraint.

Patch incoming."	Bug	closed	Database layer (models, ORM)	5.2	Release blocker	duplicate			Unreviewed	1	0	0	0	0	0
