On Aug 30, 8:19 pm, Bjorn Ruud <[EMAIL PROTECTED]> wrote: > > > On 8/29/07, Bjorn Ruud <[EMAIL PROTECTED]> wrote: > > > > The pool QuerySet gets re-evaluated when the count() in the loop is > > > run. Since one of the fields in the filter gets changed, the amount of > > > objects in the QuerySet will be different. If pool.count() is replaced > > > with len(pool) this does not happen. Is this intended behaviour? Can a > > > QuerySet be made immutable? > > On Aug 29, 3:03 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > > > This behaviour is by design. > > > queryset.count() actually constructs (and executes) a new 'SELECT > > COUNT(*) FROM table' query. This means that it will always return the > > current number of objects matching the query. In your case, the number > > of objects is changing, so count() will return a different value each > > time. > > > len(queryset) returns the length of the evaluated queryset. When the > > queryset is evaluated for the first time, it will act as a cache, so > > all calls to len(queryset) will return the same value. > > Ah, I misunderstood how the caching mechanism works. I thought that > after the initial evaluation the QuerySet was static no matter what > operation was performed since only the cache was being used. Technically you are correct - the problem is you didn't evaluate the QuerySet. If you had, say by using len(pool) the first time, then your future pool.count()s wouldn't use a query. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---