#31105: Search within an array in JSON Field
-------------------------------------+-------------------------------------
               Reporter:  Tharshan   |          Owner:  nobody
  Muthulingam                        |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  2.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Searching for a value inside an array contained in a JSONField structure,
 was possible with the Django 2.0.8

 However, it results in an exception when using Django 2.2


 {{{
   File "/Users/viperfx/Projects/sample/sample/utils.py", line 61, in
 update_user_crontab_schedule
     member_reports = Report.objects.filter(team=team,
 data__users__contains=member_id)
   File "/Users/viperfx/.pyenv/versions/env/lib/python3.7/site-
 packages/django/db/models/query.py", line 274, in __iter__
     self._fetch_all()
   File "/Users/viperfx/.pyenv/versions/env/lib/python3.7/site-
 packages/django/db/models/query.py", line 1242, in _fetch_all
     self._result_cache = list(self._iterable_class(self))
   File "/Users/viperfx/.pyenv/versions/env/lib/python3.7/site-
 packages/django/db/models/query.py", line 55, in __iter__
     results = compiler.execute_sql(chunked_fetch=self.chunked_fetch,
 chunk_size=self.chunk_size)
   File "/Users/viperfx/.pyenv/versions/env/lib/python3.7/site-
 packages/django/db/models/sql/compiler.py", line 1087, in execute_sql
     sql, params = self.as_sql()
   File "/Users/viperfx/.pyenv/versions/env/lib/python3.7/site-
 packages/django/db/models/sql/compiler.py", line 489, in as_sql
     where, w_params = self.compile(self.where) if self.where is not None
 else ("", [])
   File "/Users/viperfx/.pyenv/versions/env/lib/python3.7/site-
 packages/django/db/models/sql/compiler.py", line 405, in compile
     sql, params = node.as_sql(self, self.connection)
   File "/Users/viperfx/.pyenv/versions/env/lib/python3.7/site-
 packages/django/db/models/sql/where.py", line 81, in as_sql
     sql, params = compiler.compile(child)
   File "/Users/viperfx/.pyenv/versions/env/lib/python3.7/site-
 packages/django/db/models/sql/compiler.py", line 405, in compile
     sql, params = node.as_sql(self, self.connection)
   File "/Users/viperfx/.pyenv/versions/env/lib/python3.7/site-
 packages/django/contrib/postgres/lookups.py", line 11, in as_sql
     params = lhs_params + rhs_params
 TypeError: can only concatenate tuple (not "list") to tuple
 }}}

 The query being executed is

 {{{
 member_reports = Report.objects.filter(team=team,
 data__users__contains=member_id)
 }}}


 The sample of the JSONField that is being queried:


 {{{
 {
     "users": ["1n7HPbf7yxBqECykJ0mk3uCubFRAI1ee8IFk",
 "QYNz3iXyMGhi0TmQn2L0Ke4Y9xk6xkEGu9lM3wPVscmqODA7yw"]
 }
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31105>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.557f36373259ddff6db6856b5ed5632a%40djangoproject.com.

Reply via email to