File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -2339,6 +2339,9 @@ def set_group_by(self, allow_aliases=True):
2339
2339
self .append_annotation_mask (group_by_annotations )
2340
2340
self .select = tuple (values_select .values ())
2341
2341
self .values_select = tuple (values_select )
2342
+ if self .selected is not None :
2343
+ for index , value_select in enumerate (values_select ):
2344
+ self .selected [value_select ] = index
2342
2345
group_by = list (self .select )
2343
2346
for alias , annotation in self .annotation_select .items ():
2344
2347
if not (group_by_cols := annotation .get_group_by_cols ()):
Original file line number Diff line number Diff line change
8000
@@ -9,4 +9,6 @@ Django 5.2.1 fixes several bugs in 5.2.
9
9
Bugfixes
10
10
========
11
11
12
- * ...
12
+ * Fixed a regression in Django 5.2 that caused a crash when annotating
13
+ aggregate expressions over query that uses explicit grouping by transforms
14
+ followed by field references (:ticket:`36292`).
Original file line number Diff line number Diff line change @@ -2210,6 +2210,33 @@ def test_multiple_aggregate_references(self):
2210
2210
},
2211
2211
)
2212
2212
2213
+ def test_group_by_transform_column (self ):
2214
+ self .assertSequenceEqual (
2215
+ Store .objects .values (
2216
+ "original_opening__date" ,
2217
+ "name" ,
2218
+ )
2219
+ .annotate (Count ("books" ))
2220
+ .order_by ("name" ),
2221
+ [
2222
+ {
2223
+ "original_opening__date" : datetime .date (1994 , 4 , 23 ),
2224
+ "name" : "Amazon.com" ,
2225
+ "books__count" : 6 ,
2226
+ },
2227
+ {
2228
+ "original_opening__date" : datetime .date (2001 , 3 , 15 ),
2229
+ "name" : "Books.com" ,
2230
+ "books__count" : 4 ,
2231
+ },
2232
+ {
2233
+ "original_opening__date" : datetime .date (1945 , 4 , 25 ),
2234
+ "name" : "Mamma and Pappa's Books" ,
2235
+ "books__count" : 3 ,
2236
+ },
2237
+ ],
2238
+ )
2239
+
2213
2240
def test_group_by_reference_subquery (self ):
2214
2241
author_qs = (
2215
2242
Author .objects .annotate (publisher_id = F ("book__publisher" ))
You can’t perform that action at this time.
0 commit comments