diff options
| author | Tim Graham <timograham@gmail.com> | 2015-05-13 09:52:19 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-05-13 10:31:59 -0400 |
| commit | 3c8fe5dddf34533a419d2deed5208a28de32cb4a (patch) | |
| tree | ada2a961ac10d89bb02270d5f05d2b96aabc4b9d | |
| parent | 81d4ce4a6d21f0e65cabb253927770b3616cb560 (diff) | |
Fixed #24751 -- Fixed HStoreField isnull lookup.
| -rw-r--r-- | django/contrib/postgres/fields/hstore.py | 2 | ||||
| -rw-r--r-- | docs/releases/1.8.2.txt | 2 | ||||
| -rw-r--r-- | tests/postgres_tests/test_hstore.py | 11 |
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 ed88e2fab5..e63eda46b9 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}]' |
