Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#24169 closed Bug (fixed)

ArrayField can't use __contained_by or __overlap queries for CharField

Reported by: Joel Burton Owned by: Marc Tamlyn <marc.tamlyn@…>
Component: contrib.postgres Version: 1.8alpha1
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Joel Burton)

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.

Attachments (1)

array.py-patch (1.7 KB) - added by Joel Burton 6 years ago.
Patch, along with tests

Download all attachments as: .zip

Change History (5)

comment:1 Changed 6 years ago by Joel Burton

Description: modified (diff)

Changed 6 years ago by Joel Burton

Attachment: array.py-patch added

Patch, along with tests

comment:2 Changed 6 years ago by Tim Graham

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

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.

comment:3 Changed 6 years ago by Marc Tamlyn <marc.tamlyn@…>

Owner: set to Marc Tamlyn <marc.tamlyn@…>
Resolution: fixed
Status: newclosed

In 0ae94d0d3127adabcb0afaf32fd5dbe47d74cd57:

Fixes #24169 -- More arrayfield specific lookups.

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

Thanks to joelburton for the patch.

comment:4 Changed 6 years ago by Marc Tamlyn <marc.tamlyn@…>

In 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

Note: See TracTickets for help on using tickets.
Back to Top