#30788: Fix concatenation of tuple to list (or vice versa)
-------------------------------------+-------------------------------------
Reporter: Dmitry | Owner: nobody
Mugtasimov |
Type: Bug | Status: new
Component: Database | Version: 2.2
layer (models, ORM) |
Severity: Normal | Keywords: postgresql
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Sometimes you may get
{{{
TypeError: can only concatenate tuple (not "list") to tuple
}}}
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.
--
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/054.f029b05784f8884870e72510a0c8283b%40djangoproject.com.