summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-03-02 06:08:02 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2009-03-02 06:08:02 +0000
commit851461aa72cc94e7000c3c7713e1d9fb130e0fda (patch)
treeac0effa9cf756402383ee408c7aeee550b22d7d4
parenta605a8fe085f207092f2e330cf1e738d58c75f70 (diff)
Fixed #10181 -- Handle an EmptyResultSet exception case properly in nested querysets.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9951 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/models/sql/where.py2
-rw-r--r--tests/regressiontests/queries/models.py13
2 files changed, 9 insertions, 6 deletions
diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py
index 43ac42489a..a711103485 100644
--- a/django/db/models/sql/where.py
+++ b/django/db/models/sql/where.py
@@ -50,7 +50,7 @@ class WhereNode(tree.Node):
if hasattr(obj, "process"):
try:
obj, params = obj.process(lookup_type, value)
- except EmptyShortCircuit:
+ except (EmptyShortCircuit, EmptyResultSet):
# There are situations where we want to short-circuit any
# comparisons and make sure that nothing is returned. One
# example is when checking for a NULL pk value, or the
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
index 6d0ee8c9a9..727a537e43 100644
--- a/tests/regressiontests/queries/models.py
+++ b/tests/regressiontests/queries/models.py
@@ -1048,11 +1048,14 @@ performance problems on backends like MySQL.
[<Annotation: a1>]
Nested queries should not evaluate the inner query as part of constructing the
-SQL. This test verifies this: if the inner query is evaluated, the outer "in"
-lookup will raise an EmptyResultSet exception (as the inner query returns
-nothing).
->>> print Annotation.objects.filter(notes__in=Note.objects.filter(note="xyzzy")).query
-SELECT ...
+SQL (so we should see a nested query here, indicated by two "SELECT" calls).
+>>> Annotation.objects.filter(notes__in=Note.objects.filter(note="xyzzy")).query.as_sql()[0].count('SELECT')
+2
+
+Bug #10181 -- Avoid raising an EmptyResultSet if an inner query is provably
+empty (and hence, not executed).
+>>> Tag.objects.filter(id__in=Tag.objects.filter(id__in=[]))
+[]
Bug #9997 -- If a ValuesList or Values queryset is passed as an inner query, we
make sure it's only requesting a single value and use that as the thing to