Opened 8 years ago
Closed 8 years ago
#28281 closed Bug (duplicate)
Queryset.count() with a union takes the first id of the results objects
Reported by: | Amir Tugendhaft | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.11 |
Severity: | Normal | Keywords: | Queryset, count, union |
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 query I built with 2 querysets with a union between them, and I get a wrong count for them.
For each one of them the queryset.count() is correct, but after the union the queryset.count() is the first id of the objects results.
I used queeryset.query to see the raw query and its fine.
I'm attaching 2 photos so you could see the problem:
The first - showing 33 results is when I used '|' with the 2 querysets.
This workaround is not good for me, since the UNION's advantage is that I get the first query's results on top of the rest
The second - showing 25103 results is when I used the .union()
Attachments (2)
Change History (3)
by , 8 years ago
Attachment: | 2017-06-07 (4)_LI.jpg added |
---|
comment:1 by , 8 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
QuerySet.count()
isn't supported for unioned querysets, however, this doesn't raise an error yet, see #27995 for adding that.
Using .union()