Opened 9 years ago
Last modified 17 months ago
#26056 closed New feature
ArrayField does not work with ValueListQuerySet — at Version 2
Reported by: | Przemek | Owned by: | |
---|---|---|---|
Component: | contrib.postgres | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Basically queries of type:
A.objects.filter(array_field__overlap=B.objects.filter(foo).values_list('id', flat=True))
fail at Python level:
Traceback (most recent call last): File "failing.py", line 9, in <module> UserList.objects.filter(users__overlap=User.objects.all().values_list('id', flat=True)).count() File "/home/przemek/.virtualenvs/italamo/lib/python2.7/site-packages/Django-1.8.5-py2.7.egg/django/db/models/query.py", line 318, in count return self.query.get_count(using=self.db) File "/home/przemek/.virtualenvs/italamo/lib/python2.7/site-packages/Django-1.8.5-py2.7.egg/django/db/models/sql/query.py", line 466, in get_count number = obj.get_aggregation(using, ['__count'])['__count'] File "/home/przemek/.virtualenvs/italamo/lib/python2.7/site-packages/Django-1.8.5-py2.7.egg/django/db/models/sql/query.py", line 447, in get_aggregation result = compiler.execute_sql(SINGLE) File "/home/przemek/.virtualenvs/italamo/lib/python2.7/site-packages/Django-1.8.5-py2.7.egg/django/db/models/sql/compiler.py", line 829, in execute_sql sql, params = self.as_sql() File "/home/przemek/.virtualenvs/italamo/lib/python2.7/site-packages/Django-1.8.5-py2.7.egg/django/db/models/sql/compiler.py", line 387, in as_sql where, w_params = self.compile(self.query.where) File "/home/przemek/.virtualenvs/italamo/lib/python2.7/site-packages/Django-1.8.5-py2.7.egg/django/db/models/sql/compiler.py", line 357, in compile sql, params = node.as_sql(self, self.connection) File "/home/przemek/.virtualenvs/italamo/lib/python2.7/site-packages/Django-1.8.5-py2.7.egg/django/db/models/sql/where.py", line 104, in as_sql sql, params = compiler.compile(child) File "/home/przemek/.virtualenvs/italamo/lib/python2.7/site-packages/Django-1.8.5-py2.7.egg/django/db/models/sql/compiler.py", line 357, in compile sql, params = node.as_sql(self, self.connection) File "/home/przemek/.virtualenvs/italamo/lib/python2.7/site-packages/Django-1.8.5-py2.7.egg/django/contrib/postgres/fields/array.py", line 183, in as_sql sql, params = super(ArrayOverlap, self).as_sql(qn, connection) File "/home/przemek/.virtualenvs/italamo/lib/python2.7/site-packages/Django-1.8.5-py2.7.egg/django/contrib/postgres/lookups.py", line 8, in as_sql params = lhs_params + rhs_params TypeError: can only concatenate list (not "tuple") to list
Toy project to reproduce this behavior can be found here: https://github.com/CGenie/django_array_join_fail
This fails in 1.8 as well as in 1.9.
Change History (2)
comment:1 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Bug → New feature |
Version: | 1.9 → master |
comment:2 by , 9 years ago
Description: | modified (diff) |
---|
Note:
See TracTickets
for help on using tickets.
Accepting as a new feature by assuming you meant
B.objects.filter(foo).values('pk')
in your reported example.The implementation could simply use the PostgreSQL
array()
function to wrap the queryset.