As you see it happens because lhs_params is tuple and rhs_params is list.
{{{
def as_sql(self, qn, connection):
lhs, lhs_params = self.process_lhs(qn, connection)
rhs, rhs_params = self.process_rhs(qn, connection)
> params = lhs_params + rhs_params
E TypeError: can only concatenate tuple (not "list") to tuple
connection = <django.db.backends.postgresql.base.DatabaseWrapper object at
0x7f4845880b38>
lhs = '(SELECT ARRAY_AGG(U0."experience_id" ) AS
"experience_levels" FROM "jobs_jobtitleexperiencetrough" U0 WHERE
U0."title_id" = ANY(("jobs_job"."titles")))'
lhs_params = ()
qn = <django.db.models.sql.compiler.SQLCompiler object at
0x7f483d658860>
rhs = '%s'
rhs_params = [(21,)]
self = <django.contrib.postgres.fields.array.ArrayContains object at
0x7f483d67a0f0>
}}}
This is because of implementation of PostgresSimpleLookup:
{{{
class PostgresSimpleLookup(Lookup):
def as_sql(self, qn, connection):
lhs, lhs_params = self.process_lhs(qn, connection)
rhs, rhs_params = self.process_rhs(qn, connection)
params = lhs_params + rhs_params
return '%s %s %s' % (lhs, self.operator, rhs), params
}}}
I use this workaround:
{{{
class FixedArrayContains(DataContains):
def super_as_sql(self, qn, connection):
lhs, lhs_params = self.process_lhs(qn, connection)
rhs, rhs_params = self.process_rhs(qn, connection)
params = list(lhs_params) + list(rhs_params)
return '%s %s %s' % (lhs, self.operator, rhs), params
def as_sql(self, qn, connection):
sql, params = self.super_as_sql(qn, connection)
sql = '%s::%s' % (sql, self.lhs.output_field.db_type(connection))
return sql, params
}}}
Please, provide a solution
--
Ticket URL: <https://code.djangoproject.com/ticket/30788>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* version: 2.2 => master
* resolution: => needsinfo
Comment:
Thanks for the report, however I cannot reproduce this issue on
bae05bcf68710cb6dafa51325c3ec83ddda83c39. Can you provide models and a
queryset?
--
Ticket URL: <https://code.djangoproject.com/ticket/30788#comment:1>
* status: closed => new
* resolution: needsinfo =>
Comment:
I can confirm this is a BUG introduced in v2.2.6 most likely in
https://code.djangoproject.com/ticket/30769
In my case was about a QuerySet with a filter on a JSONField
Here my model
{{{
class CustomFieldDefinition(models.Model):
"""
Custom field
"""
....
metadata = JSONField(
verbose_name="Additional information relative to the field.",
default=dict,
)
}}}
and this is my queryset
{{{
qs = CustomFieldDefinition.objects.filter(pk__in=values) \
.filter(metadata__LDAP__has_key='attributename') \
.values_list('metadata', flat=True)
}}}
as soon as I run
{{{
qs.all()
}}}
I get the same error
in v2.2.5 the code works
--
Ticket URL: <https://code.djangoproject.com/ticket/30788#comment:2>
* cc: mcosta74 (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/30788#comment:3>
* status: new => closed
* resolution: => fixed
Comment:
Please provide the full traceback of the exception you are encountering.
It's almost impossible to trace down without it.
--
Ticket URL: <https://code.djangoproject.com/ticket/30788#comment:4>
Comment (by Simon Charette):
I suspect
https://github.com/django/django/blob/67e7dffe9543aff259f63c8f12d15642fe7be100/django/contrib/postgres/fields/jsonb.py#L110
is the culprit here.
--
Ticket URL: <https://code.djangoproject.com/ticket/30788#comment:5>
* resolution: fixed => duplicate
Comment:
Looks like a duplicate of #30826. Letting this one closed because the
other has the regression test attached.
Thanks for reporting!
--
Ticket URL: <https://code.djangoproject.com/ticket/30788#comment:6>