Author: mtredinnick
Date: 2009-03-02 00:08:02 -0600 (Mon, 02 Mar 2009)
New Revision: 9951

Modified:
   django/trunk/django/db/models/sql/where.py
   django/trunk/tests/regressiontests/queries/models.py
Log:
Fixed #10181 -- Handle an EmptyResultSet exception case properly in nested 
querysets.

Modified: django/trunk/django/db/models/sql/where.py
===================================================================
--- django/trunk/django/db/models/sql/where.py  2009-03-02 05:47:25 UTC (rev 
9950)
+++ django/trunk/django/db/models/sql/where.py  2009-03-02 06:08:02 UTC (rev 
9951)
@@ -50,7 +50,7 @@
         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

Modified: django/trunk/tests/regressiontests/queries/models.py
===================================================================
--- django/trunk/tests/regressiontests/queries/models.py        2009-03-02 
05:47:25 UTC (rev 9950)
+++ django/trunk/tests/regressiontests/queries/models.py        2009-03-02 
06:08:02 UTC (rev 9951)
@@ -1048,12 +1048,15 @@
 [<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
 select.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to