[Django] #24169: ArrayField can't use __contained_by or __overlap queries for CharField

66 views
Skip to first unread message

Django

unread,
Jan 17, 2015, 2:02:06 PM1/17/15
to django-...@googlegroups.com
#24169: ArrayField can't use __contained_by or __overlap queries for CharField
----------------------------------+-----------------------
Reporter: joelburton | Owner:
Type: Uncategorized | Status: new
Component: contrib.postgres | Version: 1.8alpha1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
----------------------------------+-----------------------
ArrayField's lookup.py uses the @> operator for __contains, the <@
operator for __contained_by, and the && operator for __overlap.

When the field uses CharField (Postgres' varchar()), __contains works, but
__contained_by and __overlap do not, as Postgres does not define <@ and &&
operators for an array of varchar[] (it does for text[]).

__contains works because, in array.py, there is a custom lookup,
"ArrayOverlap", the outputs a cast to cast the array query value to, say,
"::varchar(10)[]"

If there are similar custom lookups for __contained_by and __overlap,
these then work.

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

Django

unread,
Jan 17, 2015, 2:04:22 PM1/17/15
to django-...@googlegroups.com
#24169: ArrayField can't use __contained_by or __overlap queries for CharField
----------------------------------+--------------------------------------

Reporter: joelburton | Owner:
Type: Uncategorized | Status: new
Component: contrib.postgres | Version: 1.8alpha1
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
----------------------------------+--------------------------------------
Changes (by joelburton):

* needs_docs: => 0
* needs_tests: => 0
* needs_better_patch: => 0


Old description:

> ArrayField's lookup.py uses the @> operator for __contains, the <@
> operator for __contained_by, and the && operator for __overlap.
>
> When the field uses CharField (Postgres' varchar()), __contains works,
> but __contained_by and __overlap do not, as Postgres does not define <@
> and && operators for an array of varchar[] (it does for text[]).
>
> __contains works because, in array.py, there is a custom lookup,
> "ArrayOverlap", the outputs a cast to cast the array query value to, say,
> "::varchar(10)[]"
>
> If there are similar custom lookups for __contained_by and __overlap,
> these then work.

New description:

ArrayField's lookup.py uses the @> operator for !__contains, the <@
operator for !__contained_by, and the && operator for !__overlap.

When the field uses CharField (Postgres' varchar()), !__contains works,
but !__contained_by and !__overlap do not, as Postgres does not define <@


and && operators for an array of varchar[] (it does for text[]).

!__contains works because, in array.py, there is a custom lookup,


"ArrayOverlap", the outputs a cast to cast the array query value to, say,
"::varchar(10)[]"

If there are similar custom lookups for !__contained_by and !__overlap,
these then work.

--

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

Django

unread,
Jan 19, 2015, 6:59:04 PM1/19/15
to django-...@googlegroups.com
#24169: ArrayField can't use __contained_by or __overlap queries for CharField
----------------------------------+-------------------------------------
Reporter: joelburton | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8alpha1
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 timgraham):

* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

Any chance you could send a pull request on GitHub? That makes it quite a
bit easier to review the patch, run the tests, and merge it.

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

Django

unread,
Jan 20, 2015, 5:22:54 AM1/20/15
to django-...@googlegroups.com
#24169: ArrayField can't use __contained_by or __overlap queries for CharField
-------------------------------------+-------------------------------------
Reporter: joelburton | Owner: Marc
| Tamlyn <marc.tamlyn@…>
Type: Bug | Status: closed
Component: contrib.postgres | Version: 1.8alpha1
Severity: Normal | Resolution: fixed

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 Marc Tamlyn <marc.tamlyn@…>):

* status: new => closed
* owner: => Marc Tamlyn <marc.tamlyn@…>
* resolution: => fixed


Comment:

In [changeset:"0ae94d0d3127adabcb0afaf32fd5dbe47d74cd57"]:
{{{
#!CommitTicketReference repository=""
revision="0ae94d0d3127adabcb0afaf32fd5dbe47d74cd57"
Fixes #24169 -- More arrayfield specific lookups.

varchar()[] cannot compare itself to text[]

Thanks to joelburton for the patch.
}}}

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

Django

unread,
Jan 20, 2015, 5:27:09 AM1/20/15
to django-...@googlegroups.com
#24169: ArrayField can't use __contained_by or __overlap queries for CharField
-------------------------------------+-------------------------------------
Reporter: joelburton | Owner: Marc
| Tamlyn <marc.tamlyn@…>
Type: Bug | Status: closed
Component: contrib.postgres | Version: 1.8alpha1

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Marc Tamlyn <marc.tamlyn@…>):

In [changeset:"c80b2144d22d29725cf4d584bfa9079dd35af064"]:
{{{
#!CommitTicketReference repository=""
revision="c80b2144d22d29725cf4d584bfa9079dd35af064"
[1.8.x] Fixes #24169 -- More arrayfield specific lookups.

varchar()[] cannot compare itself to text[]

Thanks to joelburton for the patch.

Backport of 0ae94d0d31 from master
}}}

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

Reply all
Reply to author
Forward
0 new messages