summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-04-13 03:22:38 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-04-13 03:22:38 +0000
commited23f00a0007116a695adadc53d642ab90823823 (patch)
treee696dd199aeecddf5a585a66e80b92fff4c04d15
parentcfb706385b6225e9bcc028b1f8eb5aec462fc161 (diff)
Fixed #6899 -- Fixed a problem with boolean evaluation of empty querysets.
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
-rw-r--r--django/db/models/query.py3
-rw-r--r--tests/regressiontests/queries/models.py6
2 files changed, 8 insertions, 1 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index e6eb9bfd8e..1b1cdfe5fa 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -72,7 +72,8 @@ class _QuerySet(object):
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."
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
index 9b86d60fde..39f13d616d 100644
--- a/tests/regressiontests/queries/models.py
+++ b/tests/regressiontests/queries/models.py
@@ -584,6 +584,12 @@ Test that parallel iterators work.
>>> 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