#26056: ArrayField does not work with ValueListQuerySet
-------------------------------------+-------------------------------------
Reporter: Przemek | Owner: bcail
Type: New feature | Status: closed
Component: contrib.postgres | Version: dev
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Martin Lehoux):
Hi! I feel late to the battle, because I just upgraded from Django 4.1 to
Django 4.2, and I have an issue with this improvement.
I'll try to give a short example.
{{{
class Post(Model):
name = CharField()
tags = ArrayField(CharField())
class User(Model):
post = ForeignKey(Post)
current_post = Post.objects.filter(pk=OuterRef("post"))
matching_posts =
Post.objects.filter(Q(tags__overlap=current_post.values("tags"))
user = User.objects.annotate(matching_posts=matching_posts.values("name"))
}}}
This worked well before because we rely on current_post.values to return a
single value.
But now, this current_post.values is wrapped with a call to Array, and I
get `cannot accumulate empty arrays` error if the post has no tags.
Before:
{{{
WHERE tags && (SELECT tags FROM posts WHERE id = 123)
}}}
Now:
{{{
WHERE tags && ARRAY(SELECT tags FROM posts WHERE id = 123)
}}}
Maybe there is another (and better) way to achieve this, but it seems that
it has broken my use of .values in the right side.
If this is not clear enough, please tell me and I will setup a more
thorough example (I haven't tested this one, it's extracted from my work
codebase).
--
Ticket URL: <https://code.djangoproject.com/ticket/26056#comment:17>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/010701891b2d6bdb-d8380b8c-dffb-4214-aaee-c45d78ffdcde-000000%40eu-central-1.amazonses.com.