#10089 closed (fixed)
Aggregation breaks QuerySet.count() with empty results
Reported by: | Kyle Fox | Owned by: | David Larlet |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | queryset, execute_sql, aggregation, count, filter, in | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Pull Requests: | How to create a pull request | ||
Description ¶
When calling count()
after performing an __in=[]
filter, a TypeError is thrown (see example). This is because BaseQuery.get_aggregation is attempting to zip query.execute_sql(SINGLE)
(line 301), which can evaluate to None in Line 1933:
# Works, even if the filter returns no results. User.objects.filter(id__in=[1,2,3]).count() User.objects.filter(id__in=[99,100,101]).count() # Breaks: Filtering with an empty list and then calling `count()` throws an error. User.objects.filter(id__in=[]).count()
I'm not sure how to fix this problem. I'm assuming that a return value of None
is the intended behavior of execute_sql
in this case, and that get_aggregation
should be make more robust to handle a result of None.
Change History (4)
by , 16 years ago
Attachment: | patch_django_10089.20090121diff added |
---|
comment:1 by , 16 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:2 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
First naive approach