From 3c8fe5dddf34533a419d2deed5208a28de32cb4a Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 13 May 2015 09:52:19 -0400 Subject: [PATCH] Fixed #24751 -- Fixed HStoreField isnull lookup. --- django/contrib/postgres/fields/hstore.py | 2 +- docs/releases/1.8.2.txt | 2 ++ tests/postgres_tests/test_hstore.py | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/django/contrib/postgres/fields/hstore.py b/django/contrib/postgres/fields/hstore.py index 461fa047e2a..b8e47edf177 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 457dac40343..23483c2a5ef 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 ed88e2fab5d..e63eda46b96 100644 --- a/tests/postgres_tests/test_hstore.py +++ b/tests/postgres_tests/test_hstore.py @@ -114,6 +114,17 @@ class TestQuerying(PostgresSQLTestCase): 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(PostgresSQLTestCase): test_data = '[{"fields": {"field": "{\\"a\\": \\"b\\"}"}, "model": "postgres_tests.hstoremodel", "pk": null}]'