#29108 closed Bug (fixed)
QuerySet.distinct().order_by()[slice].count() crashes with "TypeError: can only concatenate tuple (not "list") to tuple"
Reported by: | Stephen Brooks | Owned by: | Simon Charette |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 2.0 |
Severity: | Release blocker | Keywords: | TypeError list tuple |
Cc: | Mariusz Felisiak | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Seen in django version 2.0.2
A model query triggers line 1448 in the file django/db/models/sql/compiler.py to raise a TypeError:
params = params + self.query.sub_params
TypeError exception: can only concatenate tuple (not "list") to tuple
This line is in the as_sql
method of the SQLAggregateCompiler
class.
How to reproduce:
Issue a query on a model which is related to another model, and include distinct, order_by (on a string field in the related model), a slice and a call to count().
e.g.
Post.objects.distinct().order_by('author__last_name')[:20].count()
The presence of distinct()
above, you could argue, is not needed, however, the above represents a simplification of the more complex query with which I originally saw the problem, and there the distinct()
followed a more complex cross-table filter.
Change History (7)
comment:1 by , 7 years ago
Cc: | added |
---|
follow-up: 3 comment:2 by , 7 years ago
comment:3 by , 7 years ago
Replying to felixxm:
Can you give more details about a
Post
andAuthor
models? I couldn't reproduce this issue.
They are just sample model names. The important thing is that there is a foreign key relationship from Post to Author so that the query can do an order_by on a char field in the related model.
When trying to reproduce it, don't leave out any of: distinct, order_by(a char field in the related model), slice, and count.
comment:4 by , 7 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|---|
Severity: | Normal → Release blocker |
Summary: | TypeError: can only concatenate tuple (not "list") to tuple raised by compiler.py → QuerySet.distinct().order_by()[slice].count() crashes with "TypeError: can only concatenate tuple (not "list") to tuple" |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
I reproduced with Book.objects.distinct().order_by('publisher__name')[:20].count()
for tests/aggregation
(not the right place commit the test). Bisected to 4acae21846f6212aa992763e587c7e201828d7b0.
comment:5 by , 7 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
Can you give more details about a
Post
andAuthor
models? I couldn't reproduce this issue.