[Django] #29429: Postgres ArrayField doesn't work properly.

22 views
Skip to first unread message

Django

unread,
May 22, 2018, 9:22:38 AM5/22/18
to django-...@googlegroups.com
#29429: Postgres ArrayField doesn't work properly.
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
creative3000 |
Type: Bug | Status: new
Component: Database | Version: 2.0
layer (models, ORM) | Keywords: db orm ArrayField
Severity: Normal | postgres
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
When you filter by len like in documentation example:
Post.objects.filter(tags__len=1)
But if you try to annotate something an error pops up example:
Post.objects.all().annotate(tag_len=F('tags__len'))
It really seems that it should work by default, but instead I needed to
use something like this
Post.objects.all().annotate(tag_len=Func(F('tags'), 1,
function='array_length'))

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

Django

unread,
May 22, 2018, 9:23:46 AM5/22/18
to django-...@googlegroups.com
#29429: Postgres ArrayField doesn't work properly.
-------------------------------------+-------------------------------------
Reporter: creative3000 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: db orm ArrayField | Triage Stage:
postgres | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by creative3000:

Old description:

> When you filter by len like in documentation example:
> Post.objects.filter(tags__len=1)
> But if you try to annotate something an error pops up example:
> Post.objects.all().annotate(tag_len=F('tags__len'))
> It really seems that it should work by default, but instead I needed to
> use something like this
> Post.objects.all().annotate(tag_len=Func(F('tags'), 1,
> function='array_length'))

New description:

When you filter by len like in documentation example:
"Post.objects.filter(tags__len=1)"
But if you try to annotate something an error pops up example:
"Post.objects.all().annotate(tag_len=F('tags__len'))"
It really seems that it should work by default, but instead I needed to
use something like this
"Post.objects.all().annotate(tag_len=Func(F('tags'), 1,
function='array_length'))"

--

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

Django

unread,
May 22, 2018, 9:30:19 AM5/22/18
to django-...@googlegroups.com
#29429: Postgres ArrayField doesn't work properly.
-------------------------------------+-------------------------------------
Reporter: creative3000 | Owner:
| creative3000
Type: Bug | Status: assigned

Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: db orm ArrayField | Triage Stage:
postgres | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by creative3000):

* owner: nobody => creative3000
* status: new => assigned


Old description:

> When you filter by len like in documentation example:
> "Post.objects.filter(tags__len=1)"
> But if you try to annotate something an error pops up example:
> "Post.objects.all().annotate(tag_len=F('tags__len'))"
> It really seems that it should work by default, but instead I needed to
> use something like this
> "Post.objects.all().annotate(tag_len=Func(F('tags'), 1,
> function='array_length'))"

New description:

When you filter by len like in documentation example:

{{{
#!python
Post.objects.filter(tags__len=1)
}}}

But if you try to annotate something an error pops up example:

{{{
#!python


Post.objects.all().annotate(tag_len=F('tags__len'))
}}}
It really seems that it should work by default, but instead I needed to
use something like this

{{{
#!python


Post.objects.all().annotate(tag_len=Func(F('tags'), 1,
function='array_length'))
}}}

--

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

Django

unread,
May 22, 2018, 2:57:08 PM5/22/18
to django-...@googlegroups.com
#29429: Make len lookup for ArrayField use the array_length function

-------------------------------------+-------------------------------------
Reporter: creative3000 | Owner:
| creative3000
Type: Bug | Status: assigned
Component: contrib.postgres | Version: 2.0
Severity: Normal | Resolution:
Keywords: db orm ArrayField | Triage Stage: Accepted
postgres |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* component: Database layer (models, ORM) => contrib.postgres
* easy: 1 => 0
* stage: Unreviewed => Accepted


Comment:

I haven't dug into this. It might be fine. Accepting for further
investigation.

--
Ticket URL: <https://code.djangoproject.com/ticket/29429#comment:3>

Django

unread,
May 25, 2018, 4:20:17 AM5/25/18
to django-...@googlegroups.com
#29429: Make len lookup for ArrayField use the array_length function
-------------------------------------+-------------------------------------
Reporter: creative3000 | Owner: (none)
Type: Bug | Status: new

Component: contrib.postgres | Version: 2.0
Severity: Normal | Resolution:
Keywords: db orm ArrayField | Triage Stage: Accepted
postgres |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by creative3000):

* owner: creative3000 => (none)
* status: assigned => new


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

Django

unread,
Jul 27, 2019, 12:40:57 PM7/27/19
to django-...@googlegroups.com
#29429: Make len lookup for ArrayField use the array_length function
-------------------------------------+-------------------------------------
Reporter: creative3000 | Owner: (none)
Type: Bug | Status: closed
Component: contrib.postgres | Version: 2.0
Severity: Normal | Resolution: needsinfo

Keywords: db orm ArrayField | Triage Stage: Accepted
postgres |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* status: new => closed
* resolution: => needsinfo


Comment:

Are you sure the line
`Post.objects.all().annotate(tag_len=F('tags__len'))` is valid?
Where did you read in the documentation a similar construct with a
Transform inside a `F()` expression?

In my opinion, you should have written:
{{{
from django.contrib.postgres.fields.array import ArrayLenTransform
Post.objects.all().annotate(tag_len=ArrayLenTransform('tags'))
}}}

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

Reply all
Reply to author
Forward
0 new messages