evals / django-aggregate-default
missing-flag
Expected
Hidden from the reviewer, like the grading note below.
- summary-flags
- violation
The wrapper no longer receives is_summary, which reintroduces the ticket's crash for aggregate() with default after annotate(). A favorable conclusion is a missed violation.
Change
django/db/models/aggregates.py
-3+1
64 unmodified lines6566676869706869707164 unmodified lines if hasattr(default, 'resolve_expression'): default = default.resolve_expression(query, allow_joins, reuse, summarize) c.default = None # Reset the default argument before wrapping. coalesce = Coalesce(c, default, output_field=c._output_field_or_none) coalesce.is_summary = c.is_summary return coalesce return Coalesce(c, default, output_field=c._output_field_or_none)
@property def default_alias(self):Contracts
summary-flags
---
name: summary-flags
message: A wrapper around a resolved aggregate inherits its summary flag.
---
## Rules
When `Aggregate.resolve_expression` wraps the resolved aggregate in `Coalesce` for a `default`, the wrapper's
`is_summary` equals the wrapped aggregate's `is_summary`.
Do not set it to a constant. `annotate()` resolves aggregates through the same path with `summarize=False`, and a
wrapper marked as a summary there can break subquery pushdown.
The wrapper must carry the flag; returning a `Coalesce` without it breaks `aggregate()` with `default`.
`Func.resolve_expression`, which `Aggregate.resolve_expression` calls first, sets the resolved aggregate's
`is_summary` to the `summarize` argument.
## Checks
From the Django root, run `./runtests.py aggregation aggregation_regress annotations`.