#10089: Aggregation breaks QuerySet.count() with empty results -------------------------------------------------------------------+-------- Reporter: Kyle Fox | Owner: nobody Status: new | Milestone: post-1.0 Component: Database layer (models, ORM) | Version: SVN Keywords: queryset, execute_sql, aggregation, count, filter, in | Stage: Unreviewed Has_patch: 0 | -------------------------------------------------------------------+-------- When calling `count()` after performing an `__in=[]` filter, a TypeError is thrown (see example). This is because [http://code.djangoproject.com/browser/django/trunk/django/db/models/sql/query.py#L262 BaseQuery.get_aggregation ] is attempting to zip `query.execute_sql(SINGLE)` (line 301), which can evaluate to None in [http://code.djangoproject.com/browser/django/trunk/django/db/models/sql/query.py#L1914 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. -- Ticket URL: <http://code.djangoproject.com/ticket/10089> Django <http://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 post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---