Browse files

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...
1 parent cfb7063 commit ed23f00a0007116a695adadc53d642ab90823823 @malcolmt malcolmt committed Apr 13, 2008
Showing with 8 additions and 1 deletion.
  1. +2 −1 django/db/models/query.py
  2. +6 −0 tests/regressiontests/queries/models.py
View
3 django/db/models/query.py
@@ -72,7 +72,8 @@ def __nonzero__(self):
iter(self).next()
except StopIteration:
return False
- return True
+ return True
+ return bool(self._result_cache)
def __getitem__(self, k):
"Retrieve an item or slice from the set of results."
View
6 tests/regressiontests/queries/models.py
@@ -584,6 +584,12 @@ class Meta:
>>> i1.next()
<Tag: t3>
+>>> qs = X.objects.all()
+>>> bool(qs)
+False
+>>> bool(qs)
+False
+
We can do slicing beyond what is currently in the result cache, too.
# FIXME!! This next test causes really weird PostgreSQL behaviour, but it's

0 comments on commit ed23f00

Please sign in to comment.