#30855: JSON has_key causes 'TypeError: can only concatenate tuple (not "list")
to
tuple' in Django 2.2.6
-----------------------------------------+------------------------
Reporter: Shaheed Haque | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
In Django 2.2.6, but not in Django 2.2.5, this query causes the exception
shown:
{{{
>>> models.PayRun.objects.filter(snapshot__employee__has_key='6')
Traceback (most recent call last):
File "/usr/lib/python3.6/code.py", line 91, in runcode
exec(code, self.locals)
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py",
line 250, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py",
line 274, in __iter__
self._fetch_all()
File "/usr/local/lib/python3.6/dist-packages/django/db/models/query.py",
line 1242, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/usr/local/lib/python3.6/dist-packages/viewflow/managers.py", line
87, in __iter__
for process in base_iterator:
File "/usr/local/lib/python3.6/dist-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 "/usr/local/lib/python3.6/dist-
packages/django/db/models/sql/compiler.py", line 1087, in execute_sql
sql, params = self.as_sql()
File "/usr/local/lib/python3.6/dist-
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 "/usr/local/lib/python3.6/dist-
packages/django/db/models/sql/compiler.py", line 405, in compile
sql, params = node.as_sql(self, self.connection)
File "/usr/local/lib/python3.6/dist-
packages/django/db/models/sql/where.py", line 81, in as_sql
sql, params = compiler.compile(child)
File "/usr/local/lib/python3.6/dist-
packages/django/db/models/sql/compiler.py", line 405, in compile
sql, params = node.as_sql(self, self.connection)
File "/usr/local/lib/python3.6/dist-
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 model field in question looks like this:
{{{
snapshot = JSONField(encoder=DjangoJSONEncoder, default=dict,
blank=True)
}}}
The code and variables
[https://github.com/django/django/blob/dafdfd6a60638c4edcca7c4e65d11c0af654d759/django/contrib/postgres/lookups.py#L11
at the point of failure] look like this:
{{{
(Pdb) list
6
7 class PostgresSimpleLookup(Lookup):
8 def as_sql(self, qn, connection):
9 lhs, lhs_params = self.process_lhs(qn, connection)
10 rhs, rhs_params = self.process_rhs(qn, connection)
11 B-> params = lhs_params + rhs_params
12 return '%s %s %s' % (lhs, self.operator, rhs), params
13
14
15 class DataContains(PostgresSimpleLookup):
16 lookup_name = 'contains'
(Pdb) lhs
'("paiyroll_payrun"."snapshot" -> %s)'
(Pdb) lhs_params
('employee',)
(Pdb) rhs
'%s'
(Pdb) rhs_params
['6']
}}}
Thus, process_lhs() and process_rhs() are producing results which cannot
be combined.
--
Ticket URL: <https://code.djangoproject.com/ticket/30855>
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/055.ef1efc5a5eb8d2c0bd9067b020fd99db%40djangoproject.com.