Opened 8 years ago
Last modified 3 years ago
#27095 new Bug
Queries involving postgres Array fields can't include expressions as elements
Reported by: | Matthew Wilkes | Owned by: | |
---|---|---|---|
Component: | contrib.postgres | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Issue #22288 allows use of expressions in lookups that take iterables rather than single items directly. This allows, for example:
NullableIntegerArrayModel.objects.filter(field__in=[models.F('field')]),
i.e., filtering an ArrayField using __in
with expressions that evaluate to other ArrayField references.
However, the following fails:
NullableIntegerArrayModel.objects.filter(field__in=[[models.F('id')]]),
i.e., building a new array that contains scalar expressions.
There are some tests, marked with expectedFailure, in postgres_tests.test_array
: test_in_including_F_object
and test_contained_by_including_F_object
, that demonstrate this problem.
Change History (11)
comment:1 by , 8 years ago
Component: | Database layer (models, ORM) → contrib.postgres |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 8 years ago
comment:4 by , 8 years ago
comment:5 by , 8 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:6 by , 4 years ago
Has patch: | set |
---|---|
Owner: | set to |
Status: | new → assigned |
I've created a PR (https://github.com/django/django/pull/13680) to fix the issue of allowing expressions on ArrayField lookups where the right-hand side is a list. Note that this PR does not fix the issue of expressions in nested lists, it should in my opinion be tracked as a separate ticket. I'm not really familiar with the process of splitting up tickets, would it make sense to create a new ticket for the nested expressions in the case of this PR being merged?
comment:7 by , 4 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:9 by , 4 years ago
Has patch: | unset |
---|---|
Triage Stage: | Ready for checkin → Accepted |
Nested arrays still don't work with expressions.
comment:11 by , 3 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
Im unable to locate the postgres_tests.test_array: test_in_including_F_object and test_contained_by_including_F_object in the master branch.
Can you please point me to the correct location?
It would be great if you can build an example, so we both are on the same page.