diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2018-01-25 20:28:34 -0800 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-01-26 10:22:14 -0500 |
| commit | 61c74ae74f6e23e5c6468c1bc2adb348c60cc289 (patch) | |
| tree | 0de99b9989c39e2a54c6520fdc8cf806c104cfb5 | |
| parent | d06381debcd175962f8c6395555f21c5f54a36fc (diff) | |
[2.0.x] Fixed #29067 -- Fixed regression in QuerySet.values_list(..., flat=True) followed by annotate().
Regression in 4dfd6b88d520b43b6363946e5ee58ba14cd1efe6.
Backport of 3187c89d6f8c60ca7e78093d5b37e0709e71cea9 from master
| -rw-r--r-- | django/db/models/query.py | 4 | ||||
| -rw-r--r-- | docs/releases/2.0.2.txt | 3 | ||||
| -rw-r--r-- | tests/aggregation_regress/tests.py | 5 |
3 files changed, 10 insertions, 2 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py index 8c22eb5d4f..ddedc8bdb5 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -7,7 +7,6 @@ import operator import warnings from collections import OrderedDict, namedtuple from functools import lru_cache -from itertools import chain from django.conf import settings from django.core import exceptions @@ -176,7 +175,8 @@ class FlatValuesListIterable(BaseIterable): def __iter__(self): queryset = self.queryset compiler = queryset.query.get_compiler(queryset.db) - return chain.from_iterable(compiler.results_iter(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)) + for row in compiler.results_iter(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size): + yield row[0] class QuerySet: diff --git a/docs/releases/2.0.2.txt b/docs/releases/2.0.2.txt index 92026be5f8..4a06ccb792 100644 --- a/docs/releases/2.0.2.txt +++ b/docs/releases/2.0.2.txt @@ -14,3 +14,6 @@ Bugfixes * Fixed incorrect foreign key nullification if a model has two foreign keys to the same model and a target model is deleted (:ticket:`29016`). + +* Fixed regression in the use of ``QuerySet.values_list(..., flat=True)`` + followed by ``annotate()`` (:ticket:`29067`). diff --git a/tests/aggregation_regress/tests.py b/tests/aggregation_regress/tests.py index 91e993a6d1..9c8bac0d21 100644 --- a/tests/aggregation_regress/tests.py +++ b/tests/aggregation_regress/tests.py @@ -1475,6 +1475,11 @@ class AggregationTests(TestCase): vals2 = Book.objects.aggregate(result=Sum('rating') - Value(4.0)) self.assertEqual(vals1, vals2) + def test_annotate_values_list_flat(self): + """Find ages that are shared by at least two authors.""" + qs = Author.objects.values_list('age', flat=True).annotate(age_count=Count('age')).filter(age_count__gt=1) + self.assertSequenceEqual(qs, [29]) + class JoinPromotionTests(TestCase): def test_ticket_21150(self): |
