[Django] #27095: Queries involving postgres Array fields can't include expressions as elements

10 views
Skip to first unread message

Django

unread,
Aug 19, 2016, 11:13:43 AM8/19/16
to django-...@googlegroups.com
#27095: Queries involving postgres Array fields can't include expressions as
elements
----------------------------------------------+--------------------
Reporter: MatthewWilkes | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer (models, ORM) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
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.

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

Django

unread,
Aug 19, 2016, 11:16:53 AM8/19/16
to django-...@googlegroups.com
#27095: Queries involving postgres Array fields can't include expressions as
elements
----------------------------------+------------------------------------
Reporter: MatthewWilkes | Owner: nobody
Type: Bug | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* component: Database layer (models, ORM) => contrib.postgres
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


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

Django

unread,
Aug 24, 2016, 8:15:17 PM8/24/16
to django-...@googlegroups.com
#27095: Queries involving postgres Array fields can't include expressions as
elements
----------------------------------+------------------------------------
Reporter: MatthewWilkes | Owner: PREM1980
Type: Bug | Status: assigned

Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by PREM1980):

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


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

Django

unread,
Aug 29, 2016, 12:22:24 PM8/29/16
to django-...@googlegroups.com
#27095: Queries involving postgres Array fields can't include expressions as
elements
----------------------------------+------------------------------------
Reporter: MatthewWilkes | Owner: PREM1980
Type: Bug | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------

Comment (by PREM1980):

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.

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

Django

unread,
Aug 29, 2016, 1:03:21 PM8/29/16
to django-...@googlegroups.com
#27095: Queries involving postgres Array fields can't include expressions as
elements
----------------------------------+------------------------------------
Reporter: MatthewWilkes | Owner: PREM1980
Type: Bug | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------

Comment (by timgraham):

https://github.com/django/django/blob/674e3fe13e5156344bfafbea59018b8837eb3044/tests/postgres_tests/test_array.py#L176-L208

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

Django

unread,
Sep 19, 2016, 10:10:24 AM9/19/16
to django-...@googlegroups.com
#27095: Queries involving postgres Array fields can't include expressions as
elements
----------------------------------+------------------------------------
Reporter: MatthewWilkes | Owner:
Type: Bug | Status: new

Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by PREM1980):

* owner: PREM1980 =>
* status: assigned => new


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

Django

unread,
Nov 20, 2020, 1:53:44 PM11/20/20
to django-...@googlegroups.com
#27095: Queries involving postgres Array fields can't include expressions as
elements
-------------------------------------+-------------------------------------
Reporter: Matthew Wilkes | Owner: Hannes
| Ljungberg
Type: Bug | Status: assigned

Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hannes Ljungberg):

* owner: (none) => Hannes Ljungberg


* status: new => assigned

* has_patch: 0 => 1


Comment:

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?

--
Ticket URL: <https://code.djangoproject.com/ticket/27095#comment:6>

Django

unread,
Nov 26, 2020, 4:27:05 AM11/26/20
to django-...@googlegroups.com
#27095: Queries involving postgres Array fields can't include expressions as
elements
-------------------------------------+-------------------------------------
Reporter: Matthew Wilkes | Owner: Hannes
| Ljungberg
Type: Bug | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
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
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/27095#comment:7>

Django

unread,
Nov 26, 2020, 2:38:46 PM11/26/20
to django-...@googlegroups.com
#27095: Queries involving postgres Array fields can't include expressions as
elements
-------------------------------------+-------------------------------------
Reporter: Matthew Wilkes | Owner: Hannes
| Ljungberg
Type: Bug | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
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 Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"33403bf80f635577a18426bc99c8a65e31fd8dfa" 33403bf8]:
{{{
#!CommitTicketReference repository=""
revision="33403bf80f635577a18426bc99c8a65e31fd8dfa"
Refs #27095 -- Allowed (non-nested) arrays containing expressions for
ArrayField lookups.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27095#comment:8>

Django

unread,
Nov 26, 2020, 2:39:54 PM11/26/20
to django-...@googlegroups.com
#27095: Queries involving postgres Array fields can't include expressions as
elements
-------------------------------------+-------------------------------------
Reporter: Matthew Wilkes | Owner: Hannes
| Ljungberg
Type: Bug | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 1 => 0
* stage: Ready for checkin => Accepted


Comment:

Nested arrays still don't work with expressions.

--
Ticket URL: <https://code.djangoproject.com/ticket/27095#comment:9>

Django

unread,
Dec 3, 2020, 3:30:54 AM12/3/20
to django-...@googlegroups.com
#27095: Queries involving postgres Array fields can't include expressions as
elements
-------------------------------------+-------------------------------------
Reporter: Matthew Wilkes | Owner: Hannes
| Ljungberg
Type: Bug | Status: assigned
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by GitHub <noreply@…>):

In [changeset:"d746f28949c009251a8741ba03d156964050717f" d746f289]:
{{{
#!CommitTicketReference repository=""
revision="d746f28949c009251a8741ba03d156964050717f"
Refs #27095 -- Fixed test_contained_by_including_F_object when run in
reverse.

Tests should not rely on auto PKs.

Test regression in 33403bf80f635577a18426bc99c8a65e31fd8dfa.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27095#comment:10>

Django

unread,
Dec 7, 2021, 2:02:32 AM12/7/21
to django-...@googlegroups.com
#27095: Queries involving postgres Array fields can't include expressions as
elements
----------------------------------+------------------------------------
Reporter: Matthew Wilkes | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: dev

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* owner: Hannes Ljungberg => (none)


* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/27095#comment:11>

Reply all
Reply to author
Forward
0 new messages