summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2019-12-17 01:21:13 -0500
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-12-19 11:10:33 +0100
commitfd9050589f5f99d61bf1c68917a9157c1e8c3752 (patch)
tree7fdbda3c79f6b16c395f3e77cb0708051eba2ded /tests
parentfb260ad777deeb61596a03a37f917d4b78ca73ae (diff)
downloaddjango-fd9050589f5f99d61bf1c68917a9157c1e8c3752.tar.gz
[3.0.x] Fixed #31094 -- Included columns referenced by subqueries in GROUP BY on aggregations.
Thanks Johannes Hoppe for the report. Regression in fb3f034f1c63160c0ff13c609acd01c18be12f80. Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com> Backport of 5a4d7285bd10bd40d9f7e574a7c421eb21094858 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/aggregation/tests.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py
index 0f799c4bc3..5ba2e180e0 100644
--- a/tests/aggregation/tests.py
+++ b/tests/aggregation/tests.py
@@ -1170,3 +1170,23 @@ class AggregateTestCase(TestCase):
Exists(long_books_qs),
).annotate(total=Count('*'))
self.assertEqual(dict(has_long_books_breakdown), {True: 2, False: 3})
+
+ def test_aggregation_subquery_annotation_related_field(self):
+ publisher = Publisher.objects.create(name=self.a9.name, num_awards=2)
+ book = Book.objects.create(
+ isbn='159059999', name='Test book.', pages=819, rating=2.5,
+ price=Decimal('14.44'), contact=self.a9, publisher=publisher,
+ pubdate=datetime.date(2019, 12, 6),
+ )
+ book.authors.add(self.a5, self.a6, self.a7)
+ books_qs = Book.objects.annotate(
+ contact_publisher=Subquery(
+ Publisher.objects.filter(
+ pk=OuterRef('publisher'),
+ name=OuterRef('contact__name'),
+ ).values('name')[:1],
+ )
+ ).filter(
+ contact_publisher__isnull=False,
+ ).annotate(count=Count('authors'))
+ self.assertSequenceEqual(books_qs, [book])