Opened 15 months ago

Last modified 14 months 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: master
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 (5)

comment:1 Changed 15 months ago by Tim Graham

Component: Database layer (models, ORM)contrib.postgres
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:2 Changed 15 months ago by PREMANAND

Owner: changed from nobody to PREMANAND
Status: newassigned

comment:3 Changed 15 months ago by PREMANAND

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.

comment:5 Changed 14 months ago by PREMANAND

Owner: PREMANAND deleted
Status: assignednew
Note: See TracTickets for help on using tickets.
Back to Top