summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Moskalets <denya.msk@gmail.com>2013-12-03 13:24:45 +0400
committerTim Graham <timograham@gmail.com>2013-12-18 09:34:53 -0500
commitd4e578d0f64971483ded49f9cae460ea174b5138 (patch)
treefd15d03814a02079a9a7e260e4648e8e0f2b16cd
parent2fd7fc134cf0c0685ceac22fd858509aa43f819f (diff)
Fixed #21552 -- Allowed the use of None for the iexact lookup.
Thanks Anubhav Joshi for the documentation.
-rw-r--r--django/db/models/sql/query.py2
-rw-r--r--docs/ref/models/querysets.txt6
-rw-r--r--docs/releases/1.7.txt3
-rw-r--r--tests/null_queries/tests.py10
4 files changed, 17 insertions, 4 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 43026d2d82..223e516d56 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -1031,7 +1031,7 @@ class Query(object):
# Interpret '__exact=None' as the sql 'is NULL'; otherwise, reject all
# uses of None as a query value.
if value is None:
- if lookup_type != 'exact':
+ if lookup_type not in ('exact', 'iexact'):
raise ValueError("Cannot use None as a query value")
lookup_type = 'isnull'
value = True
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
index fa4a09756f..e15e55d05c 100644
--- a/docs/ref/models/querysets.txt
+++ b/docs/ref/models/querysets.txt
@@ -2028,9 +2028,15 @@ iexact
Case-insensitive exact match.
+.. versionchanged:: 1.7
+
+ If the value provided for comparision is ``None``, it will be interpreted
+ as an SQL ``NULL`` (see :lookup:`isnull` for more details).
+
Example::
Blog.objects.get(name__iexact='beatles blog')
+ Blog.objects.get(name__iexact=None)
SQL equivalent::
diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt
index e4ede9913e..25b2714d42 100644
--- a/docs/releases/1.7.txt
+++ b/docs/releases/1.7.txt
@@ -450,6 +450,9 @@ Models
argument to control whether or not to perform operations in bulk
(i.e. using ``QuerySet.update()``). Defaults to ``True``.
+* It is now possible to use ``None`` as a query value for the :lookup:`iexact`
+ lookup.
+
Signals
^^^^^^^
diff --git a/tests/null_queries/tests.py b/tests/null_queries/tests.py
index e442479cd7..f807ad88ce 100644
--- a/tests/null_queries/tests.py
+++ b/tests/null_queries/tests.py
@@ -12,7 +12,8 @@ class NullQueriesTests(TestCase):
"""
Regression test for the use of None as a query value.
- None is interpreted as an SQL NULL, but only in __exact queries.
+ None is interpreted as an SQL NULL, but only in __exact and __iexact
+ queries.
Set up some initial polls and choices
"""
p1 = Poll(question='Why?')
@@ -26,6 +27,9 @@ class NullQueriesTests(TestCase):
# but every 'id' field has a value).
self.assertQuerysetEqual(Choice.objects.filter(choice__exact=None), [])
+ # The same behavior for iexact query.
+ self.assertQuerysetEqual(Choice.objects.filter(choice__iexact=None), [])
+
# Excluding the previous result returns everything.
self.assertQuerysetEqual(
Choice.objects.exclude(choice=None).order_by('id'),
@@ -38,10 +42,10 @@ class NullQueriesTests(TestCase):
# Valid query, but fails because foo isn't a keyword
self.assertRaises(FieldError, Choice.objects.filter, foo__exact=None)
- # Can't use None on anything other than __exact
+ # Can't use None on anything other than __exact and __iexact
self.assertRaises(ValueError, Choice.objects.filter, id__gt=None)
- # Can't use None on anything other than __exact
+ # Can't use None on anything other than __exact and __iexact
self.assertRaises(ValueError, Choice.objects.filter, foo__gt=None)
# Related managers use __exact=None implicitly if the object hasn't been saved.