From d976760260c2d8371c1535a7bdeba9a2e0568a34 Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Thu, 5 Jan 2017 19:03:51 -0500 Subject: [PATCH] Fixed #27693, Refs #27257 -- Fixed iexact lookup on JSONField keys. Thanks Harris Lapiroff for the report. --- django/contrib/postgres/fields/jsonb.py | 5 +++++ tests/postgres_tests/test_json.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/django/contrib/postgres/fields/jsonb.py b/django/contrib/postgres/fields/jsonb.py index b4574cc5aa..c195394409 100644 --- a/django/contrib/postgres/fields/jsonb.py +++ b/django/contrib/postgres/fields/jsonb.py @@ -133,6 +133,10 @@ class KeyTransformTextLookupMixin(object): super(KeyTransformTextLookupMixin, self).__init__(key_text_transform, *args, **kwargs) +class KeyTransformIExact(KeyTransformTextLookupMixin, builtin_lookups.IExact): + pass + + class KeyTransformIContains(KeyTransformTextLookupMixin, builtin_lookups.IContains): pass @@ -161,6 +165,7 @@ class KeyTransformIRegex(KeyTransformTextLookupMixin, builtin_lookups.IRegex): pass +KeyTransform.register_lookup(KeyTransformIExact) KeyTransform.register_lookup(KeyTransformIContains) KeyTransform.register_lookup(KeyTransformStartsWith) KeyTransform.register_lookup(KeyTransformIStartsWith) diff --git a/tests/postgres_tests/test_json.py b/tests/postgres_tests/test_json.py index 9691329a49..4e8851d485 100644 --- a/tests/postgres_tests/test_json.py +++ b/tests/postgres_tests/test_json.py @@ -238,6 +238,10 @@ class TestQuerying(PostgreSQLTestCase): self.objs[7:9] ) + def test_iexact(self): + self.assertTrue(JSONModel.objects.filter(field__foo__iexact='BaR').exists()) + self.assertFalse(JSONModel.objects.filter(field__foo__iexact='"BaR"').exists()) + def test_icontains(self): self.assertFalse(JSONModel.objects.filter(field__foo__icontains='"bar"').exists())