From ed23f00a0007116a695adadc53d642ab90823823 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sun, 13 Apr 2008 03:22:38 +0000 Subject: [PATCH] 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 --- django/db/models/query.py | 3 ++- tests/regressiontests/queries/models.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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() +>>> 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