[Django] #33898: Broken usage of ArrayAgg inside Window function

10 views
Skip to first unread message

Django

unread,
Aug 5, 2022, 9:27:06 AM8/5/22
to django-...@googlegroups.com
#33898: Broken usage of ArrayAgg inside Window function
-------------------------------------+-------------------------------------
Reporter: Kia | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 4.1
layer (models, ORM) |
Severity: Release | Keywords: ArrayAgg, Window
blocker | function, extend, tuple, params
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
The following query raises an AttributeError.

{{{

from django.contrib.postgres.aggregates import ArrayAgg
from django.db.models.expressions import Window

SampleModel.objects.all().annotate(
sample_field=Window(
expression=ArrayAgg("field_three"),
partition_by=["field_one", "field_two"],
)
)
}}}

Traceback:

{{{
File "/usr/local/lib/python3.10/site-
packages/django/db/models/expressions.py", line 1693, in as_sql
params.extend(window_params)
AttributeError: 'tuple' object has no attribute 'extend'
}}}

Works in Django 4.0.6 (maybe even in 4.0.7, didn't try) but broken in
Django 4.1.

Seems like in OrderableAggMixin
(https://github.com/django/django/blob/4.1/django/contrib/postgres/aggregates/mixins.py#L23)
it used to return a `list` as second value, but now it's a `tuple` that
breaks `params.extend()` in
https://github.com/django/django/blob/4.1/django/db/models/expressions.py#L1693

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

Reply all
Reply to author
Forward
0 new messages