mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	[2.0.x] Fixed #29067 -- Fixed regression in QuerySet.values_list(..., flat=True) followed by annotate().
Regression in4dfd6b88d5. Backport of3187c89d6ffrom master
This commit is contained in:
		| @@ -7,7 +7,6 @@ import operator | |||||||
| import warnings | import warnings | ||||||
| from collections import OrderedDict, namedtuple | from collections import OrderedDict, namedtuple | ||||||
| from functools import lru_cache | from functools import lru_cache | ||||||
| from itertools import chain |  | ||||||
|  |  | ||||||
| from django.conf import settings | from django.conf import settings | ||||||
| from django.core import exceptions | from django.core import exceptions | ||||||
| @@ -176,7 +175,8 @@ class FlatValuesListIterable(BaseIterable): | |||||||
|     def __iter__(self): |     def __iter__(self): | ||||||
|         queryset = self.queryset |         queryset = self.queryset | ||||||
|         compiler = queryset.query.get_compiler(queryset.db) |         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: | class QuerySet: | ||||||
|   | |||||||
| @@ -14,3 +14,6 @@ Bugfixes | |||||||
|  |  | ||||||
| * Fixed incorrect foreign key nullification if a model has two foreign keys to | * Fixed incorrect foreign key nullification if a model has two foreign keys to | ||||||
|   the same model and a target model is deleted (:ticket:`29016`). |   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`). | ||||||
|   | |||||||
| @@ -1475,6 +1475,11 @@ class AggregationTests(TestCase): | |||||||
|         vals2 = Book.objects.aggregate(result=Sum('rating') - Value(4.0)) |         vals2 = Book.objects.aggregate(result=Sum('rating') - Value(4.0)) | ||||||
|         self.assertEqual(vals1, vals2) |         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): | class JoinPromotionTests(TestCase): | ||||||
|     def test_ticket_21150(self): |     def test_ticket_21150(self): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user