[Django] #31916: Unexpected crash: TypeError: 'NoneType' object is not iterable

15 views
Skip to first unread message

Django

unread,
Aug 20, 2020, 9:17:15 AM8/20/20
to django-...@googlegroups.com
#31916: Unexpected crash: TypeError: 'NoneType' object is not iterable
---------------------------------------------+------------------------
Reporter: StefanosChaliasos | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version:
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
I have the following models.


{{{
from django.db import models


class M1(models.Model):
id = models.AutoField(primary_key=True,blank=True, null=True)
f1 = models.TextField(blank=True, null=True)

class Meta:
managed = False
db_table = 'm1'

class M2(models.Model):
id = models.AutoField(primary_key=True,blank=True, null=True)
f2 = models.TextField(blank=True, null=True)

class Meta:
managed = False
db_table = 'm2'

class M3(models.Model):
id = models.AutoField(primary_key=True,blank=True, null=True)
f3 = models.TextField(blank=True, null=True)

class Meta:
managed = False
db_table = 'm3'
}}}

Based on these models, I perform the following query.


{{{
o1 = M2.objects.using('default')
o2 = M1.objects.using('default')
u1 = o1.union(o2)
q = u1.order_by('-f2')
o3 = Whelped.objects.using('default')
res = q.union(o3)
print(res.count())
}}}

Unfortunately, this query crashes with a TypeError exception. The track
trace is


{{{
Traceback (most recent call last):
File "example.py", line 19, in <module>
print(res.count())
File "/home/.env/lib/python3.6/site-
packages/Django-3.2-py3.6.egg/django/db/models/query.py", line 411, in
count
return self.query.get_count(using=self.db)
File "/home/.env/lib/python3.6/site-
packages/Django-3.2-py3.6.egg/django/db/models/sql/query.py", line 517, in
get_count
number = obj.get_aggregation(using, ['__count'])['__count']
File "/home/.env/lib/python3.6/site-
packages/Django-3.2-py3.6.egg/django/db/models/sql/query.py", line 485, in
get_aggregation
outer_query.add_subquery(inner_query, using)
File "/home/.env/lib/python3.6/site-
packages/Django-3.2-py3.6.egg/django/db/models/sql/subqueries.py", line
162, in add_subquery
self.subquery, self.sub_params =
query.get_compiler(using).as_sql(with_col_aliases=True)
File "/home/.env/lib/python3.6/site-
packages/Django-3.2-py3.6.egg/django/db/models/sql/compiler.py", line 507,
in as_sql
result, params = self.get_combinator_sql(combinator,
self.query.combinator_all)
File "/home/.env/lib/python3.6/site-
packages/Django-3.2-py3.6.egg/django/db/models/sql/compiler.py", line 443,
in get_combinator_sql
if compiler.get_order_by():
File "/home/.env/lib/python3.6/site-
packages/Django-3.2-py3.6.egg/django/db/models/sql/compiler.py", line 368,
in get_order_by
for idx, (sel_expr, _, col_alias) in enumerate(self.select):
TypeError: 'NoneType' object is not iterable
}}}

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

Django

unread,
Aug 21, 2020, 9:05:11 AM8/21/20
to django-...@googlegroups.com
#31916: Combined queryset crash on combined querysets with ordering.
-------------------------------------+-------------------------------------
Reporter: StefanosChaliasos | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version:
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

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

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


Comment:

Thanks for this report. `ORDER BY` is not allowed in subqueries, however
it should raise a descriptive errror: `"ORDER BY not allowed in subqueries
of compound statements"`, even if a subquery is also a combined queryset.

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

Django

unread,
Sep 16, 2020, 9:16:26 AM9/16/20
to django-...@googlegroups.com
#31916: Combined queryset crash on combined querysets with ordering.
-------------------------------------+-------------------------------------
Reporter: StefanosChaliasos | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned

Component: Database layer | Version:
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* owner: nobody => Hasan Ramezani
* status: new => assigned
* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/13426 PR]

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

Django

unread,
Sep 17, 2020, 2:26:25 AM9/17/20
to django-...@googlegroups.com
#31916: Combined queryset crash on combined querysets with ordering.
-------------------------------------+-------------------------------------
Reporter: StefanosChaliasos | Owner: Hasan
| Ramezani
Type: Bug | Status: closed

Component: Database layer | Version:
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

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


Comment:

In [changeset:"a046bcadbee2dc0e6c889f82c08b5a21a32359ad" a046bca]:
{{{
#!CommitTicketReference repository=""
revision="a046bcadbee2dc0e6c889f82c08b5a21a32359ad"
Fixed #31916 -- Fixed combined queryset crash when combining with ordered
combined querysets.
}}}

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

Reply all
Reply to author
Forward
0 new messages