[Django] #25021: HStore values query with contains does not actually work

24 views
Skip to first unread message

Django

unread,
Jun 24, 2015, 9:13:58 AM6/24/15
to django-...@googlegroups.com
#25021: HStore values query with contains does not actually work
-------------------------------------+-------------------------------------
Reporter: amagidow | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) | Keywords: HStore, Postgresql,
Severity: Normal | queries
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
When using an HStore {{{__values}}} query with {{{__contains}}} chained on
to it, the query does not work as expected in Django 1.8.2. Expected
action is that any values which contain the text will be returned from the
query.

From my own app (I've removed some of the queryset results to make this
easier to read)

{{{
>>> query1
[<LanguageDatum: \xf0i, This (m), And, >, <LanguageDatum: hadi, This (f),
AfgA, >, <LanguageDatum: -e, His, ArBah, >, '...(remaining elements
truncated)...']
>>> query1.filter(multigloss__values__contains=["This"])
[]
>>> query1.filter(multigloss__values__contains=["This (f)"])
[<LanguageDatum: hadi, This (f), AfgA, >, <LanguageDatum: \xf0i, This
(f), ArAnz, >, '...(remaining elements truncated)...']
>>> query1.filter(multigloss__values__contains=["His"])
[<LanguageDatum: -e, His, ArBah, >, <LanguageDatum: -eh, His, ArBah, >,
<LanguageDatum: -hu, His, Chd, >, <LanguageDatum: -u, His, Chd, >
'...(remaining elements truncated)...']
>>> query1.filter(multigloss__values__contains=["Hi"])
[]
}}}

The expected result would be that the queries would return any data whose
'multigloss' values contain the string, not only those strings which are
exactly identical.


The example in the documentation should also fail if you did not include
the entire word "collie" (I have not tested, this is a hypothesized
result):

{{{
>>> Dog.objects.create(name='Rufus', data={'breed': 'labrador'})
>>> Dog.objects.create(name='Meg', data={'breed': 'collie', 'owner':
'Bob'})

>>> Dog.objects.filter(data__values__contains=['collie'])
[<Dog: Meg>]

>>>#Hypothesized example!
>>> Dog.objects.filter(data__values__contains=['coll'])
[]
>>>#Should have returned [Dog: Meg]
}}}

If this is not how {{{__values__contains}}} is supposed to work, this
should be clarified in the documentation since it is extremely unclear how
to do a search for values within the HStore that match a certain criterion
(such as containing a string).

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

Django

unread,
Jun 25, 2015, 4:40:15 PM6/25/15
to django-...@googlegroups.com
#25021: HStore values query with contains does not actually work
-------------------------------------+-------------------------------------
Reporter: amagidow | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: HStore, Postgresql, | Triage Stage:
queries | Unreviewed
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
* needs_tests: => 0
* needs_docs: => 0


Comment:

If you could provide a failing test for Django's test suite that would be
helpful.

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

Django

unread,
Jun 25, 2015, 7:36:49 PM6/25/15
to django-...@googlegroups.com
#25021: HStore values query with contains does not actually work
-------------------------------------+-------------------------------------
Reporter: amagidow | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: HStore, Postgresql, | Triage Stage:
queries | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* Attachment "ticket_25021_test.patch" added.

Django

unread,
Jun 25, 2015, 7:37:04 PM6/25/15
to django-...@googlegroups.com
#25021: HStore values query with contains does not actually work
-------------------------------------+-------------------------------------
Reporter: amagidow | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: HStore, Postgresql, | Triage Stage:
queries | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* cc: me@… (added)


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

Django

unread,
Jun 25, 2015, 7:42:12 PM6/25/15
to django-...@googlegroups.com
#25021: HStore values query with contains does not actually work
-------------------------------------+-------------------------------------
Reporter: amagidow | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: HStore, Postgresql, | Triage Stage:
queries | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by coldmind):

Seems to be postgresql behavior, I'll look deeper
{{{
dev2=# SELECT ARRAY['abc'] @> ARRAY['abc'];
?column?
----------
t
(1 row)

dev2=# SELECT ARRAY['abc'] @> ARRAY['ab'];
?column?
----------
f
(1 row)
}}}

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

Django

unread,
Jun 25, 2015, 7:55:54 PM6/25/15
to django-...@googlegroups.com
#25021: Document differences between HStore values query with contains and standard
__contains lookup

-------------------------------------+-------------------------------------
Reporter: amagidow | Owner: nobody
Type: New feature | Status: new
Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: HStore, Postgresql, | Triage Stage: Accepted
queries |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* component: Database layer (models, ORM) => Documentation
* type: Bug => New feature
* stage: Unreviewed => Accepted


Comment:

Maybe it can be hacked in some way, but I'm don't think we should change
behavior of database function here.
I'm accepting this because IMO it will be useful document differences
between
https://docs.djangoproject.com/en/1.8/ref/models/querysets/#contains and
this case, to not confuse users that may also meet this issue.

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

Django

unread,
Jun 26, 2015, 4:41:59 AM6/26/15
to django-...@googlegroups.com
#25021: Document differences between HStore values query with contains and standard
__contains lookup

-------------------------------------+-------------------------------------
Reporter: amagidow | Owner: nobody
Type: New feature | Status: closed
Component: Documentation | Version: 1.8
Severity: Normal | Resolution: invalid

Keywords: HStore, Postgresql, | Triage Stage: Accepted
queries |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* status: new => closed
* resolution: => invalid


Comment:

The array field works as expected, the ArrayField overrides the contains
lookup, see
https://docs.djangoproject.com/en/1.8/ref/contrib/postgres/fields/#contains

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

Reply all
Reply to author
Forward
0 new messages