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.
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>
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>
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>
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>
* stage: Unreviewed => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/28749#comment:5>
* 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>
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>