Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #6899 -- Fixed a problem with boolean evaluation of empty query…

…sets.

Based on patches from cide@ctmod.net and brodie.


git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7417 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ed23f00a0007116a695adadc53d642ab90823823 1 parent cfb7063
Malcolm Tredinnick authored April 13, 2008
3  django/db/models/query.py
@@ -72,7 +72,8 @@ def __nonzero__(self):
72 72
                 iter(self).next()
73 73
             except StopIteration:
74 74
                 return False
75  
-        return True
  75
+            return True
  76
+        return bool(self._result_cache)
76 77
 
77 78
     def __getitem__(self, k):
78 79
         "Retrieve an item or slice from the set of results."
6  tests/regressiontests/queries/models.py
@@ -584,6 +584,12 @@ class Meta:
584 584
 >>> i1.next()
585 585
 <Tag: t3>
586 586
 
  587
+>>> qs = X.objects.all()
  588
+>>> bool(qs)
  589
+False
  590
+>>> bool(qs)
  591
+False
  592
+
587 593
 We can do slicing beyond what is currently in the result cache, too.
588 594
 
589 595
 # FIXME!! This next test causes really weird PostgreSQL behaviour, but it's

0 notes on commit ed23f00

Please sign in to comment.
Something went wrong with that request. Please try again.