#34024: 'WhereNode' object has no attribute 'is_summary' when counting a 
queryset
with annotation from a subquery
-------------------------------------+-------------------------------------
     Reporter:  Valentin Rigal       |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  4.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by David Sanders):

 Confirmed on latest main.

 Full traceback from ipython:

 {{{
 [ins] In [1]: School.objects.annotate(
          ...:
 speciality=Subquery(Director.objects.values('speciality')[:1]),
          ...:     has_speciality=Q(speciality__isnull=False)
          ...: ).count()
 ---------------------------------------------------------------------------
 AttributeError                            Traceback (most recent call
 last)
 Cell In [1], line 4
       1 School.objects.annotate(
       2
 speciality=Subquery(Director.objects.values('speciality')[:1]),
       3     has_speciality=Q(speciality__isnull=False)
 ----> 4 ).count()

 File ~/projects/django/django/db/models/query.py:621, in
 QuerySet.count(self)
     618 if self._result_cache is not None:
     619     return len(self._result_cache)
 --> 621 return self.query.get_count(using=self.db)

 File ~/projects/django/django/db/models/sql/query.py:554, in
 Query.get_count(self, using)
     552 obj = self.clone()
     553 obj.add_annotation(Count("*"), alias="__count", is_summary=True)
 --> 554 return obj.get_aggregation(using, ["__count"])["__count"]

 File ~/projects/django/django/db/models/sql/query.py:503, in
 Query.get_aggregation(self, using, added_aggregate_names)
     501 for alias, expression in
 list(inner_query.annotation_select.items()):
     502     annotation_select_mask = inner_query.annotation_select_mask
 --> 503     if expression.is_summary:
     504         expression, col_cnt = inner_query.rewrite_cols(expression,
 col_cnt)
     505         outer_query.annotations[alias] =
 expression.relabeled_clone(
     506             relabels
     507         )

 AttributeError: 'WhereNode' object has no attribute 'is_summary'
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34024#comment:1>
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/010701835bedb0c2-9d117b7a-7d92-4bfc-a34f-62d87cf247f4-000000%40eu-central-1.amazonses.com.

Reply via email to