diff options
| author | Nuno Maltez <nuno@cognitiva.com> | 2012-07-16 19:52:31 +0300 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2012-07-16 19:52:31 +0300 |
| commit | bebbbb7af096ecffc0d7585617fdfacb196bc7c2 (patch) | |
| tree | 9e256f149ed4ac7df9894b8a637fb4f25b15f8ba /tests/modeltests/aggregation/tests.py | |
| parent | 35ddeee45573de57ae3c791bf36496b4a7028ddf (diff) | |
Fixed #18056 - Cleared aggregations on DateQuery.add_date_select
Cleared aggregations on add_date_select method so only distinct dates
are returned when dealing with a QuerySet that contained aggregations.
That would cause the query set to return repeated dates because it
would look for distinct (date kind, aggregation) pairs.
Diffstat (limited to 'tests/modeltests/aggregation/tests.py')
| -rw-r--r-- | tests/modeltests/aggregation/tests.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/modeltests/aggregation/tests.py b/tests/modeltests/aggregation/tests.py index 433ea1641a..c23b32fc85 100644 --- a/tests/modeltests/aggregation/tests.py +++ b/tests/modeltests/aggregation/tests.py @@ -565,3 +565,23 @@ class BaseAggregateTestCase(TestCase): (Decimal('82.8'), 1), ] ) + + def test_dates_with_aggregation(self): + """ + Test that .dates() returns a distinct set of dates when applied to a + QuerySet with aggregation. + + Refs #18056. Previously, .dates() would return distinct (date_kind, + aggregation) sets, in this case (year, num_authors), so 2008 would be + returned twice because there are books from 2008 with a different + number of authors. + """ + dates = Book.objects.annotate(num_authors=Count("authors")).dates('pubdate', 'year') + self.assertQuerysetEqual( + dates, [ + "datetime.datetime(1991, 1, 1, 0, 0)", + "datetime.datetime(1995, 1, 1, 0, 0)", + "datetime.datetime(2007, 1, 1, 0, 0)", + "datetime.datetime(2008, 1, 1, 0, 0)" + ] + ) |
