HStore Value__Contains Searches in Django 1.8

229 views Asked by At

I've asked this on Django.users but have no response. I have recently upgraded to Django 1.8 in order to take advantage of the native support for the HStore field (not using django-hStore), but am running into this problem. I am not sure if it is a bug, or if there is an undocumented way to do this.

I am trying to find all objects in a given model whose 'values' in their HStore field contain characters. However, the "__contains" search only works if there is an exact match between the searched item and its value.

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]

Is there a way to do the query that I'm trying to do here, or have I found a bug?

0

There are 0 answers