[Django] #34016: QuerySet.values_list crash when using ArrayAgg

8 views
Skip to first unread message

Django

unread,
Sep 16, 2022, 4:36:30 AM9/16/22
to django-...@googlegroups.com
#34016: QuerySet.values_list crash when using ArrayAgg
--------------------------------------------+------------------------
Reporter: Alex Kerkum | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: 4.1
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 |
--------------------------------------------+------------------------
Using `ArrayAgg` in combination with `values_list` results in 'TypeError:
Complex expressions require an alias'.

For example:

{{{#!python
from django.contrib.postgres.aggregates import ArrayAgg
SampleUser.objects.values_list(ArrayAgg("post_id"))

File django/db/models/aggregates.py:98, in Aggregate.default_alias(self)
96 if len(expressions) == 1 and hasattr(expressions[0], "name"):
97 return "%s__%s" % (expressions[0].name, self.name.lower())
---> 98 raise TypeError("Complex expressions require an alias")

TypeError: Complex expressions require an alias
}}}

The {{{expressions}}} variable here seems to contain {{{[F(post_id),
OrderByList()]}}} causing the {{{len[expressions]}}} check to fail. That's
as far as I got.

This still worked in 4.0.7.

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

Django

unread,
Sep 16, 2022, 4:37:53 AM9/16/22
to django-...@googlegroups.com
#34016: QuerySet.values_list crash when using ArrayAgg
----------------------------------+--------------------------------------

Reporter: Alex Kerkum | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: 4.1
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
----------------------------------+--------------------------------------
Description changed by Alex Kerkum:

Old description:

> Using `ArrayAgg` in combination with `values_list` results in 'TypeError:
> Complex expressions require an alias'.
>
> For example:
>
> {{{#!python
> from django.contrib.postgres.aggregates import ArrayAgg
> SampleUser.objects.values_list(ArrayAgg("post_id"))
>
> File django/db/models/aggregates.py:98, in Aggregate.default_alias(self)
> 96 if len(expressions) == 1 and hasattr(expressions[0], "name"):
> 97 return "%s__%s" % (expressions[0].name, self.name.lower())
> ---> 98 raise TypeError("Complex expressions require an alias")
>
> TypeError: Complex expressions require an alias
> }}}
>
> The {{{expressions}}} variable here seems to contain {{{[F(post_id),
> OrderByList()]}}} causing the {{{len[expressions]}}} check to fail.
> That's as far as I got.
>
> This still worked in 4.0.7.

New description:

Using `ArrayAgg` in combination with `values_list` results in 'TypeError:
Complex expressions require an alias'.

For example:

{{{#!python
from django.contrib.postgres.aggregates import ArrayAgg
SampleUser.objects.values_list(ArrayAgg("post_id"))

File django/db/models/aggregates.py:98, in Aggregate.default_alias(self)
96 if len(expressions) == 1 and hasattr(expressions[0], "name"):
97 return "%s__%s" % (expressions[0].name, self.name.lower())
---> 98 raise TypeError("Complex expressions require an alias")

TypeError: Complex expressions require an alias
}}}

The {{{expressions}}} variable here seems to contain {{{[F(post_id),
OrderByList()]}}} causing the {{{len[expressions]}}} check to fail. That's
as far as I got.

To me this seems related to #33898 caused by a regression in
https://github.com/django/django/commit/e06dc4571ea9fd5723c8029959b95808be9f8812

This still worked in 4.0.7.

--

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

Django

unread,
Sep 16, 2022, 4:38:40 AM9/16/22
to django-...@googlegroups.com

Old description:

> To me this seems related to #33898 caused by a regression in
> https://github.com/django/django/commit/e06dc4571ea9fd5723c8029959b95808be9f8812
>
> This still worked in 4.0.7.

New description:

Using `ArrayAgg` in combination with `values_list` results in 'TypeError:
Complex expressions require an alias'.

For example:

{{{#!python
from django.contrib.postgres.aggregates import ArrayAgg
SampleUser.objects.values_list(ArrayAgg("post_id"))

File django/db/models/aggregates.py:98, in Aggregate.default_alias(self)
96 if len(expressions) == 1 and hasattr(expressions[0], "name"):
97 return "%s__%s" % (expressions[0].name, self.name.lower())
---> 98 raise TypeError("Complex expressions require an alias")

TypeError: Complex expressions require an alias
}}}

The {{{expressions}}} variable here seems to contain {{{[F(post_id),

OrderByList()]}}} causing the {{{len(expressions)}}} check to fail. That's


as far as I got.

To me this seems related to #33898 caused by a regression in
https://github.com/django/django/commit/e06dc4571ea9fd5723c8029959b95808be9f8812

This still worked in 4.0.7.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/34016#comment:2>

Reply all
Reply to author
Forward
0 new messages