From 348ca845385beaddc7c862ff8ec369f041a5088d Mon Sep 17 00:00:00 2001 From: Clifford Gama Date: Fri, 24 Oct 2025 23:38:52 +0200 Subject: Refs #35381 -- Deprecated using None in JSONExact rhs to mean JSON null. Key and index lookups are exempt from the deprecation. Co-authored-by: Jacob Walls --- django/db/models/fields/json.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'django/db/models/fields') diff --git a/django/db/models/fields/json.py b/django/db/models/fields/json.py index 16be6846ff..819c87119a 100644 --- a/django/db/models/fields/json.py +++ b/django/db/models/fields/json.py @@ -1,4 +1,5 @@ import json +import warnings from django import forms from django.core import checks, exceptions @@ -11,6 +12,7 @@ from django.db.models.lookups import ( PostgresOperatorLookup, Transform, ) +from django.utils.deprecation import RemovedInDjango70Warning, django_file_prefixes from django.utils.translation import gettext_lazy as _ from . import Field @@ -332,10 +334,24 @@ class CaseInsensitiveMixin: class JSONExact(lookups.Exact): + # RemovedInDjango70Warning: When the deprecation period is over, remove + # the following line. can_use_none_as_rhs = True def process_rhs(self, compiler, connection): + if self.rhs is None and not isinstance(self.lhs, KeyTransform): + warnings.warn( + "Using None as the right-hand side of an exact lookup on JSONField to " + "mean JSON scalar 'null' is deprecated. Use JSONNull() instead (or use " + "the __isnull lookup if you meant SQL NULL).", + RemovedInDjango70Warning, + skip_file_prefixes=django_file_prefixes(), + ) + rhs, rhs_params = super().process_rhs(compiler, connection) + + # RemovedInDjango70Warning: When the deprecation period is over, remove + # The following if-block entirely. # Treat None lookup values as null. if rhs == "%s" and (*rhs_params,) == (None,): rhs_params = ("null",) @@ -547,6 +563,10 @@ class KeyTransformIn(lookups.In): class KeyTransformExact(JSONExact): + # RemovedInDjango70Warning: When deprecation period ends, uncomment the + # flag below. + # can_use_none_as_rhs = True + def process_rhs(self, compiler, connection): if isinstance(self.rhs, KeyTransform): return super(lookups.Exact, self).process_rhs(compiler, connection) -- cgit v1.3