Re: [Django] #33992: QuerySet.annotate() with subquery and aggregation crashes.

30 views
Skip to first unread message

Django

unread,
Sep 7, 2022, 10:40:01 PM9/7/22
to django-...@googlegroups.com
#33992: QuerySet.annotate() with subquery and aggregation crashes.
-------------------------------------+-------------------------------------
Reporter: Fernando Flores | Owner: nobody
Villaça |
Type: Bug | Status: new
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: database, orm, | Triage Stage: Accepted
aggregation |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/33992#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 7, 2022, 11:55:31 PM9/7/22
to django-...@googlegroups.com
#33992: QuerySet.annotate() with subquery and aggregation crashes.
-------------------------------------+-------------------------------------
Reporter: Fernando Flores | Owner: Simon
Villaça | Charette
Type: Bug | Status: assigned

Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: database, orm, | Triage Stage: Ready for
aggregation | checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Simon Charette
* status: new => assigned
* stage: Accepted => Ready for checkin


Comment:

[https://github.com/django/django/pull/16037 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/33992#comment:4>

Django

unread,
Sep 8, 2022, 2:13:54 AM9/8/22
to django-...@googlegroups.com
#33992: QuerySet.annotate() with subquery and aggregation crashes.
-------------------------------------+-------------------------------------
Reporter: Fernando Flores | Owner: Simon
Villaça | Charette
Type: Bug | Status: closed

Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: database, orm, | Triage Stage: Ready for
aggregation | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"e0f14d83898ee7d0d3180eb96214d8fcdf82cc1d" e0f14d8]:
{{{
#!CommitTicketReference repository=""
revision="e0f14d83898ee7d0d3180eb96214d8fcdf82cc1d"
[4.1.x] Fixed #33992 -- Fixed queryset crash when aggregating over a group
containing Exists.

A more in-depth solution is likely to make sure that we always GROUP BY
selected annotations or revisit how we use Query.exists() in the Exists
expression but that requires extra work that isn't suitable for a
backport.

Regression in e5a92d400acb4ca6a8e1375d1ab8121f2c7220be.

Thanks Fernando Flores Villaça for the report.

Backport of 32536b1324e98768dd892980408a8c6b26c23fd9 from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33992#comment:5>

Django

unread,
Sep 8, 2022, 2:13:55 AM9/8/22
to django-...@googlegroups.com
#33992: QuerySet.annotate() with subquery and aggregation crashes.
-------------------------------------+-------------------------------------
Reporter: Fernando Flores | Owner: Simon
Villaça | Charette
Type: Bug | Status: closed
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: database, orm, | Triage Stage: Ready for
aggregation | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"32536b1324e98768dd892980408a8c6b26c23fd9" 32536b1]:
{{{
#!CommitTicketReference repository=""
revision="32536b1324e98768dd892980408a8c6b26c23fd9"


Fixed #33992 -- Fixed queryset crash when aggregating over a group
containing Exists.

A more in-depth solution is likely to make sure that we always GROUP BY
selected annotations or revisit how we use Query.exists() in the Exists
expression but that requires extra work that isn't suitable for a
backport.

Regression in e5a92d400acb4ca6a8e1375d1ab8121f2c7220be.

Thanks Fernando Flores Villaça for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33992#comment:6>

Django

unread,
Oct 6, 2022, 7:54:12 AM10/6/22
to django-...@googlegroups.com
#33992: QuerySet.annotate() with subquery and aggregation crashes.
-------------------------------------+-------------------------------------
Reporter: Fernando Flores | Owner: Simon
Villaça | Charette
Type: Bug | Status: closed
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: database, orm, | Triage Stage: Ready for
aggregation | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"3d734c09ff0138441dfe0a59010435871d17950f" 3d734c0]:
{{{
#!CommitTicketReference repository=""
revision="3d734c09ff0138441dfe0a59010435871d17950f"
Refs #33992 -- Refactored subquery grouping logic.

This required moving the combined queries slicing logic to the compiler
in order to allow Query.exists() to be called at expression resolving
time.

It allowed for Query.exists() to be called at Exists() initialization
time and thus ensured that get_group_by_cols() was operating on the
terminal representation of the query that only has a single column
selected.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33992#comment:7>

Reply all
Reply to author
Forward
0 new messages