Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#31835 closed Bug (fixed)

JSONField's __contains lookup doesn't work in nested values on Oracle.

Reported by: Mariusz Felisiak Owned by: Mariusz Felisiak
Component: Database layer (models, ORM) Version: 3.1
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Oracle doesn't provide a native way for testing containment of JSONField. The current implementation works only for basic examples without supporting nested structures and doesn't follow "the general principle that the contained object must match the containing object as to structure and data contents, possibly after discarding some non-matching array elements or object key/value pairs from the containing object".

It looks that building multi-level/recursive filters with JSON_EXISTS() is the only feasible way, but it's really complicated and can be clunky.

I think we should drop this lookup on Oracle and raise NotSupportedError.

Some examples:

diff --git a/tests/model_fields/test_jsonfield.py b/tests/model_fields/test_jsonfield.py
index 3ce7fc51a9..b659675ec8 100644
--- a/tests/model_fields/test_jsonfield.py
+++ b/tests/model_fields/test_jsonfield.py
@@ -445,8 +445,12 @@ class TestQuerying(TestCase):
         tests = [
             ({}, self.objs[2:5] + self.objs[6:8]),
             ({'baz': {'a': 'b', 'c': 'd'}}, [self.objs[7]]),
+            ({'baz': {'a': 'b'}}, [self.objs[7]]),
+            ({'baz': {'c': 'd'}}, [self.objs[7]]),
             ({'k': True, 'l': False}, [self.objs[6]]),
             ({'d': ['e', {'f': 'g'}]}, [self.objs[4]]),
+            ({'d': ['e']}, [self.objs[4]]),
+            ({'d': [{'f': 'g'}]}, [self.objs[4]]),
             ([1, [2]], [self.objs[5]]),
             ({'n': [None]}, [self.objs[4]]),
             ({'j': None}, [self.objs[4]]),

Change History (4)

comment:1 by Carlton Gibson, 4 years ago

Summary: JSONField's __cointains lookup doesn't work in nested values on Oracle.JSONField's __contains lookup doesn't work in nested values on Oracle.
Triage Stage: UnreviewedAccepted

comment:2 by Mariusz Felisiak, 4 years ago

Has patch: set

comment:3 by GitHub <noreply@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In 02447fb1:

Fixed #31835 -- Dropped support for JSONField contains lookup on Oracle.

The current implementation works only for basic examples without
supporting nested structures and doesn't follow "the general principle
that the contained object must match the containing object as to
structure and data contents, possibly after discarding some
non-matching array elements or object key/value pairs from the
containing object".

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 028a5f8:

[3.1.x] Fixed #31835 -- Dropped support for JSONField contains lookup on Oracle.

The current implementation works only for basic examples without
supporting nested structures and doesn't follow "the general principle
that the contained object must match the containing object as to
structure and data contents, possibly after discarding some
non-matching array elements or object key/value pairs from the
containing object".
Backport of 02447fb133b53ec7d0ff068cc08f06fdf8817ef7 from master

Note: See TracTickets for help on using tickets.
Back to Top