[Django] #29108: TypeError: can only concatenate tuple (not "list") to tuple raised by compiler.py

8 views
Skip to first unread message

Django

unread,
Feb 2, 2018, 1:28:41 PM2/2/18
to django-...@googlegroups.com
#29108: TypeError: can only concatenate tuple (not "list") to tuple raised by
compiler.py
-------------------------------------+-------------------------------------
Reporter: Stephen | Owner: nobody
Brooks |
Type: | Status: new
Uncategorized |
Component: | Version: 2.0
Uncategorized | Keywords: TypeError list
Severity: Normal | tuple
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29108>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 2, 2018, 4:01:18 PM2/2/18
to django-...@googlegroups.com
#29108: TypeError: can only concatenate tuple (not "list") to tuple raised by
compiler.py
-------------------------------------+-------------------------------------
Reporter: Stephen Brooks | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.0
Severity: Normal | Resolution:
Keywords: TypeError list | Triage Stage:
tuple | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* cc: felixxm (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/29108#comment:1>

Django

unread,
Feb 2, 2018, 4:17:30 PM2/2/18
to django-...@googlegroups.com
#29108: TypeError: can only concatenate tuple (not "list") to tuple raised by
compiler.py
-------------------------------------+-------------------------------------
Reporter: Stephen Brooks | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.0
Severity: Normal | Resolution:
Keywords: TypeError list | Triage Stage:
tuple | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by felixxm):

Can you give more details about a `Post` and `Author` models? I couldn't
reproduce this issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/29108#comment:2>

Django

unread,
Feb 2, 2018, 4:31:09 PM2/2/18
to django-...@googlegroups.com
#29108: TypeError: can only concatenate tuple (not "list") to tuple raised by
compiler.py
-------------------------------------+-------------------------------------
Reporter: Stephen Brooks | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.0
Severity: Normal | Resolution:
Keywords: TypeError list | Triage Stage:
tuple | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Stephen Brooks):

Replying to [comment:2 felixxm]:


> Can you give more details about a `Post` and `Author` 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29108#comment:3>

Django

unread,
Feb 3, 2018, 3:38:26 PM2/3/18
to django-...@googlegroups.com
#29108: QuerySet.distinct().order_by()[slice].count() crashes with "TypeError: can

only concatenate tuple (not "list") to tuple"
-------------------------------------+-------------------------------------
Reporter: Stephen Brooks | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: TypeError list | Triage Stage: Accepted
tuple |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* component: Uncategorized => Database layer (models, ORM)
* stage: Unreviewed => Accepted
* type: Uncategorized => Bug
* severity: Normal => Release blocker


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29108#comment:4>

Django

unread,
Feb 4, 2018, 12:35:45 AM2/4/18
to django-...@googlegroups.com
#29108: QuerySet.distinct().order_by()[slice].count() crashes with "TypeError: can

only concatenate tuple (not "list") to tuple"
-------------------------------------+-------------------------------------
Reporter: Stephen Brooks | Owner: Simon
| Charette
Type: Bug | Status: assigned

Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: TypeError list | Triage Stage: Accepted
tuple |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* status: new => assigned
* owner: nobody => Simon Charette
* has_patch: 0 => 1


Comment:

https://github.com/django/django/pull/9660

--
Ticket URL: <https://code.djangoproject.com/ticket/29108#comment:5>

Django

unread,
Feb 8, 2018, 9:59:44 AM2/8/18
to django-...@googlegroups.com
#29108: QuerySet.distinct().order_by()[slice].count() crashes with "TypeError: can

only concatenate tuple (not "list") to tuple"
-------------------------------------+-------------------------------------
Reporter: Stephen Brooks | Owner: Simon
| Charette
Type: Bug | Status: closed

Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: TypeError list | Triage Stage: Accepted
tuple |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"d61fe246015aa4fdc6dcb837ffb1442fa71ae586" d61fe246]:
{{{
#!CommitTicketReference repository=""
revision="d61fe246015aa4fdc6dcb837ffb1442fa71ae586"
Fixed #29108 -- Fixed crash in aggregation of distinct+ordered+sliced
querysets.

Regression in 4acae21846f6212aa992763e587c7e201828d7b0.
Thanks Stephen Brooks for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29108#comment:6>

Django

unread,
Feb 8, 2018, 10:00:36 AM2/8/18
to django-...@googlegroups.com
#29108: QuerySet.distinct().order_by()[slice].count() crashes with "TypeError: can

only concatenate tuple (not "list") to tuple"
-------------------------------------+-------------------------------------
Reporter: Stephen Brooks | Owner: Simon
| Charette
Type: Bug | Status: closed
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: TypeError list | Triage Stage: Accepted
tuple |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"8d03356d35a91e2a8536bae4319f061ccf6c0294" 8d03356]:
{{{
#!CommitTicketReference repository=""
revision="8d03356d35a91e2a8536bae4319f061ccf6c0294"
[2.0.x] Fixed #29108 -- Fixed crash in aggregation of
distinct+ordered+sliced querysets.

Regression in 4acae21846f6212aa992763e587c7e201828d7b0.
Thanks Stephen Brooks for the report.

Backport of d61fe246015aa4fdc6dcb837ffb1442fa71ae586 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29108#comment:7>

Reply all
Reply to author
Forward
0 new messages