#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.

-- 
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/060.c72abe683021cb42325f77cd1832ce7d%40djangoproject.com.

Reply via email to