mirror of https://github.com/django/django.git
[4.2.x] Fixed #34748 -- Fixed queryset crash when grouping by a reference in a subquery.
Regression indd68af62b2
. Thanks Toan Vuong for the report. Backport of4087367ba8
from main
This commit is contained in:
parent
a52a2b6678
commit
739da73164
|
@ -1181,7 +1181,9 @@ class Ref(Expression):
|
||||||
return {self.refs}
|
return {self.refs}
|
||||||
|
|
||||||
def relabeled_clone(self, relabels):
|
def relabeled_clone(self, relabels):
|
||||||
return self
|
clone = self.copy()
|
||||||
|
clone.source = self.source.relabeled_clone(relabels)
|
||||||
|
return clone
|
||||||
|
|
||||||
def as_sql(self, compiler, connection):
|
def as_sql(self, compiler, connection):
|
||||||
return connection.ops.quote_name(self.refs), []
|
return connection.ops.quote_name(self.refs), []
|
||||||
|
|
|
@ -12,3 +12,6 @@ Bugfixes
|
||||||
* Fixed a regression in Django 4.2 that caused a crash of
|
* Fixed a regression in Django 4.2 that caused a crash of
|
||||||
``QuerySet.aggregate()`` with aggregates referencing window functions
|
``QuerySet.aggregate()`` with aggregates referencing window functions
|
||||||
(:ticket:`34717`).
|
(:ticket:`34717`).
|
||||||
|
|
||||||
|
* Fixed a regression in Django 4.2 that caused a crash when grouping by a
|
||||||
|
reference in a subquery (:ticket:`34748`).
|
||||||
|
|
|
@ -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):
|
class AggregateAnnotationPruningTests(TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Reference in New Issue