#30855 closed Bug (duplicate)
JSON has_key causes 'TypeError: can only concatenate tuple (not "list") to tuple' in Django 2.2.6
| Reported by: | Shaheed Haque | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 1.11 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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 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.
Change History (4)
comment:1 by , 6 years ago
| Component: | Uncategorized → Database layer (models, ORM) |
|---|---|
| Resolution: | → duplicate |
| Status: | new → closed |
| Type: | Uncategorized → Bug |
| Version: | 2.2 → 1.11 |
comment:3 by , 6 years ago
Hmmm. Personally, I don't think it's an emergency. v2.2.7 (&co) will already be the third pass at catching the regression(s) introduced by the security patch for v2.2.4. I'd rather hold the schedule to give us the best chance at making sure we won't need a forth. But happy if you want to raise it on the list for discussion Claude. :)
Thanks for this report, we're going to fix this in Django 2.2.7.
Duplicate of #30826.