Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #7759 -- Fixed QuerySet.count() when the results cache was only…

… partially

populated.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@7938 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 52fdedba48fc99876ab562bee2c29052953f8430 1 parent 57bb10e
@malcolmt malcolmt authored
View
7 django/db/models/query.py
@@ -280,11 +280,10 @@ def count(self):
Performs a SELECT COUNT() and returns the number of records as an
integer.
- If the QuerySet is already cached (i.e. self._result_cache is set) this
- simply returns the length of the cached results set to avoid multiple
- SELECT COUNT(*) calls.
+ If the QuerySet is already fully cached this simply returns the length
+ of the cached results set to avoid multiple SELECT COUNT(*) calls.
"""
- if self._result_cache is not None:
+ if self._result_cache is not None and not self._iter:
return len(self._result_cache)
return self.query.get_count()
View
8 tests/regressiontests/queries/models.py
@@ -830,5 +830,13 @@ class Related(models.Model):
... obj.save()
... if i > 10: break
+Bug #7759 -- count should work with a partially read result set.
+>>> count = Number.objects.count()
+>>> qs = Number.objects.all()
+>>> for obj in qs:
+... qs.count() == count
+... break
+True
+
"""}
Please sign in to comment.
Something went wrong with that request. Please try again.