mirror of
https://github.com/django/django.git
synced 2025-05-07 15:36:29 +00:00
Fixed #36292 -- Fixed crash when aggregating over a group mixing transforms and references.
Regression in 65ad4ade74dc9208b9d686a451cd6045df0c9c3a. Refs #28900 Thanks Patrick Altman for the report.
This commit is contained in:
parent
3ae049b26b
commit
543e17c440
@ -2339,6 +2339,9 @@ class Query(BaseExpression):
|
|||||||
self.append_annotation_mask(group_by_annotations)
|
self.append_annotation_mask(group_by_annotations)
|
||||||
self.select = tuple(values_select.values())
|
self.select = tuple(values_select.values())
|
||||||
self.values_select = tuple(values_select)
|
self.values_select = tuple(values_select)
|
||||||
|
if self.selected is not None:
|
||||||
|
for index, value_select in enumerate(values_select):
|
||||||
|
self.selected[value_select] = index
|
||||||
group_by = list(self.select)
|
group_by = list(self.select)
|
||||||
for alias, annotation in self.annotation_select.items():
|
for alias, annotation in self.annotation_select.items():
|
||||||
if not (group_by_cols := annotation.get_group_by_cols()):
|
if not (group_by_cols := annotation.get_group_by_cols()):
|
||||||
|
@ -9,4 +9,6 @@ Django 5.2.1 fixes several bugs in 5.2.
|
|||||||
Bugfixes
|
Bugfixes
|
||||||
========
|
========
|
||||||
|
|
||||||
* ...
|
* Fixed a regression in Django 5.2 that caused a crash when annotating
|
||||||
|
aggregate expressions over query that uses explicit grouping by transforms
|
||||||
|
followed by field references (:ticket:`36292`).
|
||||||
|
@ -2210,6 +2210,33 @@ class AggregateTestCase(TestCase):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_group_by_transform_column(self):
|
||||||
|
self.assertSequenceEqual(
|
||||||
|
Store.objects.values(
|
||||||
|
"original_opening__date",
|
||||||
|
"name",
|
||||||
|
)
|
||||||
|
.annotate(Count("books"))
|
||||||
|
.order_by("name"),
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"original_opening__date": datetime.date(1994, 4, 23),
|
||||||
|
"name": "Amazon.com",
|
||||||
|
"books__count": 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"original_opening__date": datetime.date(2001, 3, 15),
|
||||||
|
"name": "Books.com",
|
||||||
|
"books__count": 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"original_opening__date": datetime.date(1945, 4, 25),
|
||||||
|
"name": "Mamma and Pappa's Books",
|
||||||
|
"books__count": 3,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def test_group_by_reference_subquery(self):
|
def test_group_by_reference_subquery(self):
|
||||||
author_qs = (
|
author_qs = (
|
||||||
Author.objects.annotate(publisher_id=F("book__publisher"))
|
Author.objects.annotate(publisher_id=F("book__publisher"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user