#24065: aggregate dont find column of annotate
-------------------------------------+-------------------------------------
     Reporter:  mateuspadua          |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  1.7
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  aggregate annotate   |             Triage Stage:
  fielderror                         |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by mateuspadua):

 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * needs_docs:   => 0


Old description:

> If we try this query, everything works normally
>
> {{{
> Entry.objects.annotate(num_authors=Count('authors')).aggregate(Avg('num_authors'))
> }}}
>
> but if we try the one below, it does not find the column
> ''authors__count' to the aggregation
>
> {{{
> Entry.objects.annotate(Count('authors')).aggregate(Avg('authors__count'))
> }}}
>
> I believe it is a problem because the exception tells us we could use the
> column ''''authors__count''''
>
> This is what the exception says:
>
> '''FieldError: Cannot resolve keyword 'count' into field. Choices are:
> email, entry, id, name, authors__count''' <- see the field here.
>
> Thanks.

New description:

 If we try this query, everything works normally

 {{{
 
Entry.objects.annotate(num_authors=Count('authors')).aggregate(Avg('num_authors'))
 }}}

 but if we try the one below, it does not find the column
 {{{authors__count}}} to the aggregation

 {{{
 Entry.objects.annotate(Count('authors')).aggregate(Avg('authors__count'))
 }}}

 I believe it is a problem because the exception tells us we could use the
 column {{{authors__count}}}

 This is what the exception says:

 {{{FieldError: Cannot resolve keyword 'count' into field. Choices are:
 email, entry, id, name, authors__count}}} <- see the field here.

 Thanks.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/24065#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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.0daf7da8b6e97714a545ebd2301fb95c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to