--
Ticket URL: <https://code.djangoproject.com/ticket/29429>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
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>
* 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>
* 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>
* owner: creative3000 => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/29429#comment:4>
* 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>