Opened 7 years ago

Closed 7 years ago

#24065 closed Bug (worksforme)

aggregate dont find column of annotate

Reported by: mateuspadua Owned by: nobody
Component: Database layer (models, ORM) Version: 1.7
Severity: Normal Keywords: aggregate annotate fielderror
Cc: mateuspaduaweb@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by mateuspadua)

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.

Change History (2)

comment:1 Changed 7 years ago by mateuspadua

Description: modified (diff)

comment:2 Changed 7 years ago by Josh Smeaton

Resolution: worksforme
Status: newclosed

This works for me on current master. I haven't checked to see if it works in 1.7 because I assume it doesn't from your bug report. I think #14030 would have fixed this bug.

Note: See TracTickets for help on using tickets.
Back to Top