Changes between Initial Version and Version 2 of Ticket #37473


Ignore:
Timestamp:
Nov 3, 2026, 4:38:27 PM (3 hours ago)
Author:
cheek-walnut
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #37473

    • Property Summary QuerySet.aggregate() crashes when values() selects only an aggregate annotation → QuerySet.count() and aggregate() crash when values() selects only aggregate annotations
  • Ticket #37473 – Description

    initial v2  
    3131Expected `{'m': 40}`, as on Django 5.1, where the inner query selects `"app_author"."age" AS "__col1"`. `values_list("c")` fails the same way; `values("name", "c")` and `aggregate(m=Max("c"))` work.
    3232
    33 Regression in 65ad4ade74dc9208b9d686a451cd6045df0c9c3a (Refs #28900): the query works on its parent and fails on it. Reproduced on 5.2.20, 6.0.11, 6.1.4 and main (5bd95c57a2) with SQLite; 5.1.16 is not affected.
     33Regression in 65ad4ade74dc9208b9d686a451cd6045df0c9c3a (Refs #28900): the query works on its parent and fails on it. Reproduced on 5.2.19, 6.0.10, 6.1.3 and main with SQLite; 5.1.16 is not affected.
    3434
    3535The cause appears to be `if self.selected:` in `Query.set_annotation_mask()` (django/db/models/sql/query.py:2568) and `Query.add_annotation()` (:1248), which treats an empty `selected` dict like `None`: after `get_aggregation()` masks the unused `c` annotation, `selected` is `{}` and the `__col1` column added for the aggregate is never added to it.
Back to Top