| 1 | Index: django/db/models/sql/query.py
|
|---|
| 2 | ===================================================================
|
|---|
| 3 | --- django/db/models/sql/query.py (revision 9781)
|
|---|
| 4 | +++ django/db/models/sql/query.py (working copy)
|
|---|
| 5 | @@ -295,10 +295,14 @@
|
|---|
| 6 | query.related_select_cols = []
|
|---|
| 7 | query.related_select_fields = []
|
|---|
| 8 |
|
|---|
| 9 | + result = query.execute_sql(SINGLE)
|
|---|
| 10 | + if result is None:
|
|---|
| 11 | + return {None: 0}
|
|---|
| 12 | +
|
|---|
| 13 | return dict([
|
|---|
| 14 | (alias, self.resolve_aggregate(val, aggregate))
|
|---|
| 15 | for (alias, aggregate), val
|
|---|
| 16 | - in zip(query.aggregate_select.items(), query.execute_sql(SINGLE))
|
|---|
| 17 | + in zip(query.aggregate_select.items(), result)
|
|---|
| 18 | ])
|
|---|
| 19 |
|
|---|
| 20 | def get_count(self):
|
|---|
| 21 |
|
|---|
| 22 | Index: tests/regressiontests/aggregation_regress/models.py
|
|---|
| 23 | ===================================================================
|
|---|
| 24 | --- tests/regressiontests/aggregation_regress/models.py (revision 9781)
|
|---|
| 25 | +++ tests/regressiontests/aggregation_regress/models.py (working copy)
|
|---|
| 26 | @@ -151,6 +151,10 @@
|
|---|
| 27 | >>> Book.objects.select_related('publisher').annotate(num_authors=Count('authors')).values()[0]
|
|---|
| 28 | {'rating': 4.0, 'isbn': u'013790395', 'name': u'Artificial Intelligence: A Modern Approach', 'pubdate': datetime.date(1995, 1, 15), 'price': Decimal("82.8..."), 'id': 5, 'num_authors': 2, 'publisher_id': 3, 'pages': 1132}
|
|---|
| 29 |
|
|---|
| 30 | +# Regression for #10089: count() with empty QuerySet
|
|---|
| 31 | +>>> Book.objects.filter(id__in=[]).count()
|
|---|
| 32 | +0
|
|---|
| 33 | +
|
|---|
| 34 | """
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|