#34717 closed Bug (fixed)
Cannot use aggregate over window functions since 4.2
Reported by: | younes-chaoui | Owned by: | Simon Charette |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 4.2 |
Severity: | Release blocker | Keywords: | aggregation, window functions, psycopg |
Cc: | Simon Charette | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
After upgrading to Django 4.2, I encountered an exception when executing ORM queries that involve aggregates over Window functions. The specific error was psycopg2.errors.GroupingError: aggregate function calls cannot contain window function calls
Dependencies :
psycopg2 version: 2.9.3
django version: 4.2.3
PostgreSQL version: 13.4
Example Code:
queryset = queryset.annotate( cumul_DJR=Coalesce(Window(Sum("DJR"), order_by=F("date").asc()), 0.0) ) aggregate = queryset.aggregate( DJR_total=Sum("DJR"), cumul_DJR_total=Sum("cumul_DJR") )
Change History (10)
comment:1 by , 17 months ago
Keywords: | aggregation window functions psycopg added |
---|---|
Type: | Uncategorized → Bug |
comment:2 by , 17 months ago
Cc: | added |
---|---|
Resolution: | → needsinfo |
Status: | new → closed |
comment:3 by , 17 months ago
Component: | Uncategorized → Database layer (models, ORM) |
---|---|
Has patch: | set |
Resolution: | needsinfo |
Severity: | Normal → Release blocker |
Status: | closed → new |
Triage Stage: | Unreviewed → Accepted |
Confirmed this is a regression similar to #34551 but for window expressions.
@younes-chaoui could you confirm the following patch addresses our issue [PR](https://github.com/django/django/pull/17084)
comment:4 by , 17 months ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 17 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:8 by , 17 months ago
Description: | modified (diff) |
---|
comment:9 by , 17 months ago
Younes, it is expected that the issue isn't fixed in Django 4.2.3 (it was released on July 3rd which is 14 days before your report).
The issue will be fixed in the upcoming 4.2.4 release which is scheduled for August 1st.
Hello! Could you please provide a minimal Django test project with models to reproduce this issue? Or a regression test that would pass on Django 4.1 but fail in 4.2? Thank you!