Opened 61 minutes ago
Last modified 8 minutes ago
#37404 assigned Bug
JSONIn with Value(None, JSONField()) does not match JSON null on Oracle
| Reported by: | Clifford Gama | Owned by: | Clifford Gama |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 5.2 |
| Severity: | Normal | Keywords: | json, oracle, null, JSONIn |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
On Oracle, JSONIn.as_oracle() 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:
-
tests/model_fields/test_jsonfield.py
diff --git a/tests/model_fields/test_jsonfield.py b/tests/model_fields/test_jsonfield.py index 264b88a23d..2276b7857d 100644
a b def test_in_json_whitespace(self): 1076 1076 [obj], 1077 1077 ) 1078 1078 1079 @skipUnlessDBFeature("supports_primitives_in_json_field") 1080 @skipIfDBFeature("has_native_json_field") 1081 def test_in_value_json_typed_none_matches_json_null(self): 1082 json_null = NullableJSONModel.objects.create(value=JSONNull()) 1083 self.assertSequenceEqual( 1084 NullableJSONModel.objects.filter(value__in=[Value(None, JSONField())]), 1085 [json_null], 1086 ) 1087 1079 1088 def test_key_in(self): 1080 1089 tests = [ 1081 1090 ("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.
Change History (1)
comment:1 by , 8 minutes ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Version: | 6.1 → 5.2 |
Note:
See TracTickets
for help on using tickets.
Great, thank you!
I reproduced on 5.2 by replacing
JSONNull()in the setup step withValue(None, JSONField()). I got:On 6.1 the query succeeds, but with the wrong result.