diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-01-23 11:03:48 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-01-23 11:03:48 +0000 |
| commit | 0e15932be392ab56fa0087f9c13b234af7749e2e (patch) | |
| tree | 63dd18930c2b230f53713ce5d1fb220d9fde76a8 /tests/regressiontests/aggregation_regress | |
| parent | ed3d2735a2eb5d279e2098e14437eb9e445498c6 (diff) | |
Fixed #10089 -- Corrected handling of aggregates when the query set contains no items (and the cursor returns None). Thanks to Kyle Fox for the report, and david for the initial patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9786 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/aggregation_regress')
| -rw-r--r-- | tests/regressiontests/aggregation_regress/fixtures/initial_data.json | 8 | ||||
| -rw-r--r-- | tests/regressiontests/aggregation_regress/models.py | 10 |
2 files changed, 18 insertions, 0 deletions
diff --git a/tests/regressiontests/aggregation_regress/fixtures/initial_data.json b/tests/regressiontests/aggregation_regress/fixtures/initial_data.json index a632c4077a..7c5d62c2c6 100644 --- a/tests/regressiontests/aggregation_regress/fixtures/initial_data.json +++ b/tests/regressiontests/aggregation_regress/fixtures/initial_data.json @@ -32,6 +32,14 @@ } }, { + "pk": 5, + "model": "aggregation_regress.publisher", + "fields": { + "name": "Jonno's House of Books", + "num_awards": 0 + } + }, + { "pk": 1, "model": "aggregation_regress.book", "fields": { diff --git a/tests/regressiontests/aggregation_regress/models.py b/tests/regressiontests/aggregation_regress/models.py index 8a590dca8b..7ff54b2c0d 100644 --- a/tests/regressiontests/aggregation_regress/models.py +++ b/tests/regressiontests/aggregation_regress/models.py @@ -164,6 +164,16 @@ FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, id, i >>> len(Book.objects.annotate(num_authors=Count('authors')).exclude(num_authors__lt=2).filter(num_authors__lt=3)) 2 +# Regression for #10089: Check handling of empty result sets with aggregates +>>> Book.objects.filter(id__in=[]).count() +0 + +>>> Book.objects.filter(id__in=[]).aggregate(num_authors=Count('authors'), avg_authors=Avg('authors'), max_authors=Max('authors'), max_price=Max('price'), max_rating=Max('rating')) +{'max_authors': None, 'max_rating': None, 'num_authors': 0, 'avg_authors': None, 'max_price': None} + +>>> Publisher.objects.filter(pk=5).annotate(num_authors=Count('book__authors'), avg_authors=Avg('book__authors'), max_authors=Max('book__authors'), max_price=Max('book__price'), max_rating=Max('book__rating')).values() +[{'max_authors': None, 'name': u"Jonno's House of Books", 'num_awards': 0, 'max_price': None, 'num_authors': 0, 'max_rating': None, 'id': 5, 'avg_authors': None}] + """ } |
