summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-05-13 09:52:19 -0400
committerTim Graham <timograham@gmail.com>2015-05-13 10:34:15 -0400
commitdf0674eabb898d87d8267c5ade026dbf17fd01a8 (patch)
tree0e33f4db711dbe6039ab75d1cd12acea7960d5a0
parent7ea6477b3ad3a0da3196e5d3f5f09369e76c8cc5 (diff)
[1.8.x] Fixed #24751 -- Fixed HStoreField isnull lookup.
Backport of 3c8fe5dddf34533a419d2deed5208a28de32cb4a from master
-rw-r--r--django/contrib/postgres/fields/hstore.py2
-rw-r--r--docs/releases/1.8.2.txt2
-rw-r--r--tests/postgres_tests/test_hstore.py11
3 files changed, 14 insertions, 1 deletions
diff --git a/django/contrib/postgres/fields/hstore.py b/django/contrib/postgres/fields/hstore.py
index 461fa047e2..b8e47edf17 100644
--- a/django/contrib/postgres/fields/hstore.py
+++ b/django/contrib/postgres/fields/hstore.py
@@ -78,7 +78,7 @@ class KeyTransform(Transform):
def as_sql(self, compiler, connection):
lhs, params = compiler.compile(self.lhs)
- return "%s -> '%s'" % (lhs, self.key_name), params
+ return "(%s -> '%s')" % (lhs, self.key_name), params
class KeyTransformFactory(object):
diff --git a/docs/releases/1.8.2.txt b/docs/releases/1.8.2.txt
index 457dac4034..23483c2a5e 100644
--- a/docs/releases/1.8.2.txt
+++ b/docs/releases/1.8.2.txt
@@ -25,3 +25,5 @@ Bugfixes
pointing to :class:`~django.db.models.UUIDField` and inheritance on models
with ``UUIDField`` primary keys work correctly (:ticket:`24698`,
:ticket:`24712`).
+
+* Fixed ``isnull`` lookup for ``HStoreField`` (:ticket:`24751`).
diff --git a/tests/postgres_tests/test_hstore.py b/tests/postgres_tests/test_hstore.py
index 06544163f8..8b2cc883dc 100644
--- a/tests/postgres_tests/test_hstore.py
+++ b/tests/postgres_tests/test_hstore.py
@@ -110,6 +110,17 @@ class TestQuerying(TestCase):
self.objs[:3]
)
+ def test_key_isnull(self):
+ obj = HStoreModel.objects.create(field={'a': None})
+ self.assertSequenceEqual(
+ HStoreModel.objects.filter(field__a__isnull=True),
+ self.objs[2:5] + [obj]
+ )
+ self.assertSequenceEqual(
+ HStoreModel.objects.filter(field__a__isnull=False),
+ self.objs[:2]
+ )
+
class TestSerialization(TestCase):
test_data = '[{"fields": {"field": "{\\"a\\": \\"b\\"}"}, "model": "postgres_tests.hstoremodel", "pk": null}]'