Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit ed23f00a0007116a695adadc53d642ab90823823 1 parent cfb7063
@malcolmt malcolmt authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.