[Django] #31152: Annotating ArrayAgg and Subquery crashes

109 views
Skip to first unread message

Django

unread,
Jan 9, 2020, 9:25:47 AM1/9/20
to django-...@googlegroups.com
#31152: Annotating ArrayAgg and Subquery crashes
-----------------------------------------+------------------------
Reporter: ivasic | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 3.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Think I found a regression issue that does not happen with Django <3.0 and
does in the latest 3.x releases.

{{{
Book.objects
.annotate(
labels=ArrayAgg(
"reviews__labels",
filter=Q(reviews__labels__isnull=False),
distinct=True,
)
)
.annotate(
fav_count=Subquery(
FavoriteBook.objects.filter(book=OuterRef("pk"))
.annotate(count=Count("id"))
.values("count")[:1],
output_field=IntegerField(),
)
)
.values('id')
}}}

This crashes with

{{{
django.db.utils.ProgrammingError: column "fav_count" does not exist
LINE 1: ..._labels"."review_id") GROUP BY "myapp_book"."id", "fav_count...
^
}}}

(Disregard that it makes no sense to do annotations if we're only using
"id" values - it's for the purpose of this example)

Asking for `.values('fav_count')` works though. I've compiled a small
example project that contains all the models and a test case that
reproduces this issue.

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

Django

unread,
Jan 9, 2020, 9:26:55 AM1/9/20
to django-...@googlegroups.com
#31152: Annotating ArrayAgg and Subquery crashes
-------------------------------+--------------------------------------

Reporter: ivasic | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 3.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by ivasic):

* Attachment "proj.zip" added.

Project

Django

unread,
Jan 9, 2020, 9:33:24 AM1/9/20
to django-...@googlegroups.com
#31152: Annotating ArrayAgg and Subquery crashes with values().
-------------------------------------+-------------------------------------
Reporter: Ivan Vasić | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* resolution: => duplicate
* component: Uncategorized => Database layer (models, ORM)


Comment:

Duplicate of #31136.

--
Ticket URL: <https://code.djangoproject.com/ticket/31152#comment:1>

Reply all
Reply to author
Forward
0 new messages