Opened 4 years ago
Closed 4 years ago
#32020 closed Bug (duplicate)
Wrong multiple Count() annotations.
Reported by: | rgermain | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 3.1 |
Severity: | Normal | Keywords: | annotate Count |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have a problem when I want to add several Count, the result is incomprehensible.
individual:
User.objects.annotate(create=Count("event_creator")).values("username", "create") <QuerySet [{'username': 'rgermain', 'create': 0}]> User.objects.annotate(create=Count("eventlang_creator")).values("username", "create") <QuerySet [{'username': 'rgermain', 'create': 0}]> User.objects.annotate(create=Count("people_creator")).values("username", "create") <QuerySet [{'username': 'rgermain', 'create': 0}]> User.objects.annotate(create=Count("peoplelang_creator")).values("username", "create") <QuerySet [{'username': 'rgermain', 'create': 0}]> User.objects.annotate(create=Count("picture_creator")).values("username", "create") <QuerySet [{'username': 'rgermain', 'create': 0}]> User.objects.annotate(create=Count("picturelang_creator")).values("username", "create") <QuerySet [{'username': 'rgermain', 'create': 0}]> User.objects.annotate(create=Count("tag_creator")).values("username", "create") <QuerySet [{'username': 'rgermain', 'create': 0}]> User.objects.annotate(create=Count("taglang_creator")).values("username", "create") <QuerySet [{'username': 'rgermain', 'create': 0}]> User.objects.annotate(create=Count("translate_creator")).values("username", "create") <QuerySet [{'username': 'rgermain', 'create': 211}]> User.objects.annotate(create=Count("translatelang_creator")).values("username", "create") <QuerySet [{'username': 'rgermain', 'create': 422}]> User.objects.annotate(create=Count("video_creator")).values("username", "create") <QuerySet [{'username': 'rgermain', 'create': 0}]> User.objects.annotate(create=Count("videolang_creator")).values("username", "create") <QuerySet [{'username': 'rgermain', 'create': 0}]>
so the total is 633
(422 + 211 + 0 * 10) = 633
I would like to do it in one line so :
User.objects.annotate(create= Count("event_creator") + Count("eventlang_creator") + Count("people_creator") + Count("peoplelang_creator") + Count("picture_creator") + Count("picturelang_creator") + Count("tag_creator") + Count("taglang_creator") + Count("translate_creator") + Count("translatelang_creator") + Count("video_creator") + Count("videolang_creator") ).values("username", "create") <QuerySet [{'username': 'rgermain', 'create': 178084}]>
total is 178084, same with aggregate.
i use sqlite3.
Change History (1)
comment:1 by , 4 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Summary: | wrong multiple count annotate → Wrong multiple Count() annotations. |
Note:
See TracTickets
for help on using tickets.
This is an expected behavior, see comment. Duplicate of #29271.