Fixed #34748 -- Fixed queryset crash when grouping by a reference in a subquery.

Regression in dd68af62b2.

Thanks Toan Vuong for the report.
This commit is contained in:
Simon Charette 2023-07-28 07:45:23 -04:00 committed by Mariusz Felisiak
parent af0c5caff7
commit 4087367ba8
3 changed files with 16 additions and 1 deletions

View file

@ -2116,6 +2116,16 @@ class AggregateTestCase(TestCase):
},
)
def test_group_by_reference_subquery(self):
author_qs = (
Author.objects.annotate(publisher_id=F("book__publisher"))
.values("publisher_id")
.annotate(cnt=Count("*"))
.values("publisher_id")
)
qs = Publisher.objects.filter(pk__in=author_qs)
self.assertCountEqual(qs, [self.p1, self.p2, self.p3, self.p4])
class AggregateAnnotationPruningTests(TestCase):
@classmethod