[Django] #28749: PostgreSQL's ArrayField "in" operator does not allow subqueries

7 views
Skip to first unread message

Django

unread,
Oct 27, 2017, 6:21:42 PM10/27/17
to django-...@googlegroups.com
#28749: PostgreSQL's ArrayField "in" operator does not allow subqueries
--------------------------------------------+------------------------
Reporter: Michał Pasternak | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
Hi,

I have a legitimate use-case, where I want to filter using "in" operator a
PostgreSQL ArrayField (contrib.postgres.fields.array.ArrayField).

Current implementation does not allow that.

You will get a traceback similar to the one below:
{{{
Traceback (most recent call last):
File
"/Users/mpasternak/Programowanie/django/tests/postgres_tests/test_array.py",
line 185, in test_in_subquery
"field", flat=True)
File
"/Users/mpasternak/Programowanie/django/django/db/models/manager.py", line
82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/mpasternak/Programowanie/django/django/db/models/query.py",
line 835, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/Users/mpasternak/Programowanie/django/django/db/models/query.py",
line 853, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File
"/Users/mpasternak/Programowanie/django/django/db/models/sql/query.py",
line 1252, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File
"/Users/mpasternak/Programowanie/django/django/db/models/sql/query.py",
line 1276, in _add_q
split_subq=split_subq,
File
"/Users/mpasternak/Programowanie/django/django/db/models/sql/query.py",
line 1214, in build_filter
condition = self.build_lookup(lookups, col, value)
File
"/Users/mpasternak/Programowanie/django/django/db/models/sql/query.py",
line 1084, in build_lookup
lookup = lookup_class(lhs, rhs)
File
"/Users/mpasternak/Programowanie/django/django/db/models/lookups.py", line
18, in __init__
self.rhs = self.get_prep_lookup()
File
"/Users/mpasternak/Programowanie/django/django/contrib/postgres/fields/array.py",
line 252, in get_prep_lookup
for value in values:
TypeError: 'Query' object is not iterable
}}}

The fix seems trivial.

I implemented both the fix and the test for it in my branch here:
https://github.com/mpasternak/django .

I am submitting a pull request on GitHub in a moment.

I am planning to back port this to 1.11.x .

Not sure if this is a Bug or a Feature, classifying as Bug for now.

This is my first contribution to Django Project that, I believe, is going
to be merged. I have sent CLA as requested.

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

Django

unread,
Oct 27, 2017, 6:22:28 PM10/27/17
to django-...@googlegroups.com
#28749: PostgreSQL's ArrayField "in" operator does not allow subqueries
----------------------------------+--------------------------------------

Reporter: Michał Pasternak | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Michał Pasternak):

The pull request is here: https://github.com/django/django/pull/9300

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

Django

unread,
Oct 27, 2017, 6:32:19 PM10/27/17
to django-...@googlegroups.com
#28749: PostgreSQL's ArrayField "in" operator does not allow subqueries
----------------------------------+--------------------------------------

Reporter: Michał Pasternak | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Michał Pasternak):

Backport to 1.11.x is here: https://github.com/django/django/pull/9301

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

Django

unread,
Oct 27, 2017, 6:34:10 PM10/27/17
to django-...@googlegroups.com
#28749: PostgreSQL's ArrayField "in" operator does not allow subqueries
----------------------------------+--------------------------------------

Reporter: Michał Pasternak | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Description changed by Michał Pasternak:

Old description:

New description:

Hi,

I have a legitimate use-case, where I want to filter using "in" operator a

PostgreSQL ArrayField (contrib.postgres.fields.array.ArrayField) when
using a subquery.

The fix seems trivial.

--

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

Django

unread,
Oct 27, 2017, 6:34:42 PM10/27/17
to django-...@googlegroups.com
#28749: PostgreSQL's ArrayField "in" operator does not allow subqueries
----------------------------------+--------------------------------------

Reporter: Michał Pasternak | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Description changed by Michał Pasternak:

Old description:

> Hi,


>
> I have a legitimate use-case, where I want to filter using "in" operator

> a PostgreSQL ArrayField (contrib.postgres.fields.array.ArrayField) when
> using a subquery.
>

New description:

Hi,

I have a legitimate use-case, where I want to filter using "in" operator a

PostgreSQL ArrayField (contrib.postgres.fields.array.ArrayField) when
using a subquery.

Current implementation does not allow that.

The fix seems trivial.

(https://github.com/django/django/pull/9300).

I am planning to back port this to 1.11.x

(https://github.com/django/django/pull/9301).

Not sure if this is a Bug or a Feature, classifying as Bug for now.

This is my first contribution to Django Project that, I believe, is going
to be merged. I have sent CLA as requested.

--

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

Django

unread,
Nov 1, 2017, 3:18:30 PM11/1/17
to django-...@googlegroups.com
#28749: PostgreSQL's ArrayField "in" operator does not allow subqueries
-------------------------------------+-------------------------------------

Reporter: Michał Pasternak | Owner: (none)
Type: Bug | Status: new
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 Tim Graham):

* stage: Unreviewed => Ready for checkin


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

Django

unread,
Nov 1, 2017, 3:31:07 PM11/1/17
to django-...@googlegroups.com
#28749: PostgreSQL's ArrayField "in" operator does not allow subqueries
-------------------------------------+-------------------------------------
Reporter: Michał Pasternak | Owner: Tim
| Graham <timograham@…>
Type: Bug | Status: closed
Component: contrib.postgres | Version: master
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
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* owner: (none) => Tim Graham <timograham@…>
* resolution: => fixed


Comment:

In [changeset:"e554b72a2a5473f3f1e57a32565758757a9e8e87" e554b72]:
{{{
#!CommitTicketReference repository=""
revision="e554b72a2a5473f3f1e57a32565758757a9e8e87"
Fixed #28749 -- Added subquery support for ArrayField's __in lookup.
}}}

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

Django

unread,
Nov 1, 2017, 3:40:53 PM11/1/17
to django-...@googlegroups.com
#28749: PostgreSQL's ArrayField "in" operator does not allow subqueries
-------------------------------------+-------------------------------------
Reporter: Michał Pasternak | Owner: Tim
| Graham <timograham@…>
Type: Bug | Status: closed
Component: contrib.postgres | Version: master

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 Tim Graham <timograham@…>):

In [changeset:"e80a014fceb64a0723174c296710e6b4c04d58d0" e80a014f]:
{{{
#!CommitTicketReference repository=""
revision="e80a014fceb64a0723174c296710e6b4c04d58d0"
[2.0.x] Fixed #28749 -- Added subquery support for ArrayField's __in
lookup.

Backport of e554b72a2a5473f3f1e57a32565758757a9e8e87 from master
}}}

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

Reply all
Reply to author
Forward
0 new messages