diff options
author | Dmitry Dygalo <dadygalo@gmail.com> | 2018-02-20 16:47:12 +0100 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2018-04-04 10:53:46 -0400 |
commit | c979c0a2b8abca325a549961fd7a17bdc36bcb1f (patch) | |
tree | b6d221918b9c0989cbb3d6dc08cd7ebee08381bf /django/contrib/postgres/lookups.py | |
parent | 4fe5d846666d46a5395a5f0ea2845a96b6837a75 (diff) | |
download | django-c979c0a2b8abca325a549961fd7a17bdc36bcb1f.tar.gz |
Fixed #25718 -- Made a JSONField lookup value of None match keys that have a null value.
Diffstat (limited to 'django/contrib/postgres/lookups.py')
-rw-r--r-- | django/contrib/postgres/lookups.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/django/contrib/postgres/lookups.py b/django/contrib/postgres/lookups.py index afef01ef9e..c2b3d2b569 100644 --- a/django/contrib/postgres/lookups.py +++ b/django/contrib/postgres/lookups.py @@ -1,4 +1,5 @@ from django.db.models import Lookup, Transform +from django.db.models.lookups import Exact from .search import SearchVector, SearchVectorExact, SearchVectorField @@ -64,3 +65,12 @@ class SearchLookup(SearchVectorExact): class TrigramSimilar(PostgresSimpleLookup): lookup_name = 'trigram_similar' operator = '%%' + + +class JSONExact(Exact): + can_use_none_as_rhs = True + + def process_rhs(self, compiler, connection): + result = super().process_rhs(compiler, connection) + # Treat None lookup values as null. + return ("'null'", []) if result == ('%s', [None]) else result |