Django

Code

Changeset 7938

Show
Ignore:
Timestamp:
07/16/08 18:17:29 (4 months ago)
Author:
mtredinnick
Message:

Fixed #7759 -- Fixed QuerySet?.count() when the results cache was only partially
populated.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/query.py

    r7912 r7938  
    281281        integer. 
    282282 
    283         If the QuerySet is already cached (i.e. self._result_cache is set) this 
    284         simply returns the length of the cached results set to avoid multiple 
    285         SELECT COUNT(*) calls. 
    286         """ 
    287         if self._result_cache is not None: 
     283        If the QuerySet is already fully cached this simply returns the length 
     284        of the cached results set to avoid multiple SELECT COUNT(*) calls. 
     285        """ 
     286        if self._result_cache is not None and not self._iter: 
    288287            return len(self._result_cache) 
    289288 
  • django/trunk/tests/regressiontests/queries/models.py

    r7926 r7938  
    831831...     if i > 10: break 
    832832 
     833Bug #7759 -- count should work with a partially read result set. 
     834>>> count = Number.objects.count() 
     835>>> qs = Number.objects.all() 
     836>>> for obj in qs: 
     837...     qs.count() == count 
     838...     break 
     839True 
     840 
    833841"""} 
    834842