You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support Django's aggregations with output_field #2052
djangohas-open-prnarrowingIssues with narrowing - root cause is usually narrowing, flow handling, or bothneeds-discussionAn issue where it's not clear whether there is a bug or we are behaving as expected.
@MartinBernstorff Thank you for the report!
it is unclear to me if we should be returning dict[str, Int]. The reason is that based on the stubs, the aggregate signature is as follows: def aggregate(self, *args: Any, **kwargs: Any) -> dict[str, Any]: ....
We can consider refining that, but dict[str, Int] seems too strict. Based on the docs:
When an aggregation is applied to an empty queryset or grouping, the result defaults to its default parameter, typically None. This behavior occurs because aggregate functions return NULL when the executed query returns no rows.
so it is unclear to me if we should be adding special typechecker handing to refine the type for this.
This issue has someone assigned, but has not had recent activity for more than 2 weeks.
If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.
The same expression types are missing on annotate() attributes (they are Unknown), filed as #5734 with a repro. One rule for what each aggregate/expression returns (using output_field when given) would cover both aggregate() here and annotate() there.
djangohas-open-prnarrowingIssues with narrowing - root cause is usually narrowing, flow handling, or bothneeds-discussionAn issue where it's not clear whether there is a bug or we are behaving as expected.
Activity
MartinBernstorff commentedon Jan 9, 2026
The docs say I should add the
djangolabel, but I do not have permissions to add labels :-)migeed-z commentedon Jan 9, 2026
@MartinBernstorff Thank you for the report!
it is unclear to me if we should be returning
dict[str, Int]. The reason is that based on the stubs, the aggregate signature is as follows:def aggregate(self, *args: Any, **kwargs: Any) -> dict[str, Any]: ....We can consider refining that, but
dict[str, Int]seems too strict. Based on the docs:so it is unclear to me if we should be adding special typechecker handing to refine the type for this.
MartinBernstorff commentedon Jan 12, 2026
Good points! I still think it should be narrowed down, but I agree that it might not be
dict[str, Int].Add testcase to document aggregate behavior
github-actions commentedon Feb 11, 2026
This issue has someone assigned, but has not had recent activity for more than 2 weeks.
If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.
Thank you for your contributions!
dhruvparanjape commentedon Nov 23, 2026
The same expression types are missing on
annotate()attributes (they areUnknown), filed as #5734 with a repro. One rule for what each aggregate/expression returns (usingoutput_fieldwhen given) would cover bothaggregate()here andannotate()there.