summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2020-01-15 09:32:42 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-01-15 09:33:36 +0100
commita24686987f21fe6b5339cc13607c13fa906f81a8 (patch)
tree0fea2987450e04b3fa0098db8beccc9987e1d494 /tests
parent6aac9f6b1148bdc24dd282b9932c1ae55b489724 (diff)
[3.0.x] Refs #31136 -- Made QuerySet.values()/values_list() group only by selected annotation.
Regression in 0f843fdd5b9b2f2307148465cd60f4e1b2befbb4. Backport of 59b4e99dd00b9c36d56055b889f96885995e4240 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/aggregation/tests.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py
index 2cabeb5df8..bef415abd4 100644
--- a/tests/aggregation/tests.py
+++ b/tests/aggregation/tests.py
@@ -1163,6 +1163,31 @@ class AggregateTestCase(TestCase):
'Sams',
])
+ def test_aggregation_subquery_annotation_values(self):
+ """
+ Subquery annotations and external aliases are excluded from the GROUP
+ BY if they are not selected.
+ """
+ books_qs = Book.objects.annotate(
+ first_author_the_same_age=Subquery(
+ Author.objects.filter(
+ age=OuterRef('contact__friends__age'),
+ ).order_by('age').values('id')[:1],
+ )
+ ).filter(
+ publisher=self.p1,
+ first_author_the_same_age__isnull=False,
+ ).annotate(
+ min_age=Min('contact__friends__age'),
+ ).values('name', 'min_age').order_by('name')
+ self.assertEqual(list(books_qs), [
+ {'name': 'Practical Django Projects', 'min_age': 34},
+ {
+ 'name': 'The Definitive Guide to Django: Web Development Done Right',
+ 'min_age': 29,
+ },
+ ])
+
@skipUnlessDBFeature('supports_subqueries_in_group_by')
def test_group_by_subquery_annotation(self):
"""