#37404: JSONIn with Value(None, JSONField()) does not match JSON null on Oracle
-------------------------------------+-------------------------------------
Reporter: Clifford | Owner: Clifford Gama
Gama |
Type: Bug | Status: assigned
Component: Database | Version: 6.1
layer (models, ORM) | Keywords: json, oracle, null,
Severity: Normal | JSONIn
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
On Oracle, `JSONIn.as_oracle()`
[
https://github.com/django/django/blob/8c34887b1ad8bb3ec61c6e713442dab3c643d557/django/db/models/fields/json.py#L462
only special-cases JSONNull()] on the right-hand side. A `Value(None,
output_field=JSONField())` is not routed to the same `JSON_EQUAL` path, so
it doesn't match a JSON `null` row in `__in`. Both `JSONNull()` and
`Value(None, JSONField())` match in `__exact`.
Failing test:
{{{#!diff
diff --git a/tests/model_fields/test_jsonfield.py
b/tests/model_fields/test_jsonfield.py
index 264b88a23d..2276b7857d 100644
--- a/tests/model_fields/test_jsonfield.py
+++ b/tests/model_fields/test_jsonfield.py
@@ -1076,6 +1076,15 @@ def test_in_json_whitespace(self):
[obj],
)
+ @skipUnlessDBFeature("supports_primitives_in_json_field")
+ @skipIfDBFeature("has_native_json_field")
+ def test_in_value_json_typed_none_matches_json_null(self):
+ json_null = NullableJSONModel.objects.create(value=JSONNull())
+ self.assertSequenceEqual(
+ NullableJSONModel.objects.filter(value__in=[Value(None,
JSONField())]),
+ [json_null],
+ )
+
def test_key_in(self):
tests = [
("value__c__in", [14], self.objs[3:5]),
}}}
Found while working on #37403, but the bug predates the introduction of
JSONIn or JSONNull, so it's not a regression in 6.1.
--
Ticket URL: <
https://code.djangoproject.com/ticket/37404>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.