Browse files

Fixed #10181 -- Handle an EmptyResultSet exception case properly in n…

…ested querysets.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent a605a8f commit 851461aa72cc94e7000c3c7713e1d9fb130e0fda @malcolmt malcolmt committed Mar 2, 2009
Showing with 9 additions and 6 deletions.
  1. +1 −1 django/db/models/sql/
  2. +8 −5 tests/regressiontests/queries/
@@ -50,7 +50,7 @@ def add(self, data, connector):
if hasattr(obj, "process"):
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
@@ -1048,11 +1048,14 @@ def __unicode__(self):
[<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
->>> print Annotation.objects.filter(notes__in=Note.objects.filter(note="xyzzy")).query
+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')
+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

0 comments on commit 851461a

Please sign in to comment.