[Django] #24751: hstore isnull lookup fails

31 views
Skip to first unread message

Django

unread,
May 5, 2015, 5:16:50 AM5/5/15
to django-...@googlegroups.com
#24751: hstore isnull lookup fails
----------------------------------+--------------------
Reporter: mrAdm | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Release blocker | Keywords: hstore
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------
{{{
from django.db import models
from django.contrib.postgres.fields import HStoreField


class HStoreModel(Model):
hstore_field = HStoreField()
}}}
Execute the query:
{{{
HStoreModel.objects.create(hstore_field={'a': None})
HStoreModel.objects.filter(hstore_field__a__isnull=True)
# or non existing key
HStoreModel.objects.filter(hstore_field__b__isnull=True)
}}}
Exception:
{{{
Traceback (most recent call last):
File "/vagrant/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-
packages/django/core/management/__init__.py", line 338, in
execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-
packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line
18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py",
line 115, in populate
app_config.ready()
File "/vagrant/st/apps.py", line 12, in ready
print HStoreModel.objects.filter(hstore_field__a__isnull=True)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py",
line 138, in __repr__
data = list(self[:REPR_OUTPUT_SIZE + 1])
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py",
line 162, in __iter__
self._fetch_all()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py",
line 965, in _fetch_all
self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py",
line 238, in iterator
results = compiler.execute_sql()
File "/usr/local/lib/python2.7/dist-
packages/django/db/models/sql/compiler.py", line 829, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-
packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/local/lib/python2.7/dist-
packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line
97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python2.7/dist-
packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: operator does not exist: hstore ->
boolean
LINE 1: ...storemodel" WHERE "st_hstoremodel"."hstore_field" -> 'a' IS ...
^
HINT: No operator matches the given name and argument type(s). You might
need to add explicit type casts.
}}}
Wrong SQL syntax?:
{{{
WHERE "st_hstoremodel"."hstore_field" -> 'b' IS NULL
}}}
Maybe you need this:
{{{
WHERE ("st_hstoremodel"."hstore_field" -> 'b') IS NULL
}}}

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

Django

unread,
May 5, 2015, 8:18:32 AM5/5/15
to django-...@googlegroups.com
#24751: hstore isnull lookup fails
----------------------------------+------------------------------------

Reporter: mrAdm | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Release blocker | Resolution:
Keywords: hstore | Triage Stage: Accepted
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_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

Attaching a failing test.

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

Django

unread,
May 5, 2015, 8:18:39 AM5/5/15
to django-...@googlegroups.com
#24751: hstore isnull lookup fails
----------------------------------+------------------------------------

Reporter: mrAdm | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Release blocker | Resolution:
Keywords: hstore | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* Attachment "24751-test.diff" added.

Django

unread,
May 5, 2015, 10:09:56 AM5/5/15
to django-...@googlegroups.com
#24751: hstore isnull lookup fails
----------------------------------+------------------------------------

Reporter: mrAdm | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Release blocker | Resolution:
Keywords: hstore | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by jarshwah):

Is there any reason these hstore lookups couldn't always be wrapped in
brackets (assuming this fixes the isnull problem)? We do a similar thing
with F-combinables already:
https://github.com/django/django/blob/9096e2b5f75abf8e8882937bd3c3d47ccdc24e25/django/db/models/expressions.py#L391-L392

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

Django

unread,
May 7, 2015, 2:06:33 AM5/7/15
to django-...@googlegroups.com
#24751: hstore isnull lookup fails
----------------------------------+------------------------------------

Reporter: mrAdm | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Release blocker | Resolution:
Keywords: hstore | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by akaariai):

+1 to brackets. It should fix the isnull problem.

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

Django

unread,
May 12, 2015, 7:15:56 AM5/12/15
to django-...@googlegroups.com
#24751: hstore isnull lookup fails
----------------------------------+------------------------------------

Reporter: mrAdm | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Release blocker | Resolution:
Keywords: hstore | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by mjtamlyn):

Can't think of a reason the brackets would be a problem. We likely will
need the same thing for JSON as well.

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

Django

unread,
May 13, 2015, 9:57:14 AM5/13/15
to django-...@googlegroups.com
#24751: hstore isnull lookup fails
----------------------------------+------------------------------------

Reporter: mrAdm | Owner:
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.8
Severity: Release blocker | Resolution:
Keywords: hstore | 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):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/4652 PR]

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

Django

unread,
May 13, 2015, 10:34:47 AM5/13/15
to django-...@googlegroups.com
#24751: hstore isnull lookup fails
-------------------------------------+-------------------------------------
Reporter: mrAdm | Owner: Tim
| Graham <timograham@…>
Type: Bug | Status: closed
Component: contrib.postgres | Version: 1.8
Severity: Release blocker | Resolution: fixed

Keywords: hstore | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* owner: => Tim Graham <timograham@…>
* resolution: => fixed


Comment:

In [changeset:"3c8fe5dddf34533a419d2deed5208a28de32cb4a" 3c8fe5d]:
{{{
#!CommitTicketReference repository=""
revision="3c8fe5dddf34533a419d2deed5208a28de32cb4a"
Fixed #24751 -- Fixed HStoreField isnull lookup.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24751#comment:6>

Django

unread,
May 13, 2015, 10:35:23 AM5/13/15
to django-...@googlegroups.com
#24751: hstore isnull lookup fails
-------------------------------------+-------------------------------------
Reporter: mrAdm | Owner: Tim
| Graham <timograham@…>
Type: Bug | Status: closed
Component: contrib.postgres | Version: 1.8

Severity: Release blocker | Resolution: fixed
Keywords: hstore | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by Tim Graham <timograham@…>):

In [changeset:"df0674eabb898d87d8267c5ade026dbf17fd01a8" df0674ea]:
{{{
#!CommitTicketReference repository=""
revision="df0674eabb898d87d8267c5ade026dbf17fd01a8"
[1.8.x] Fixed #24751 -- Fixed HStoreField isnull lookup.

Backport of 3c8fe5dddf34533a419d2deed5208a28de32cb4a from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24751#comment:7>

Reply all
Reply to author
Forward
0 new messages