Hi all,

I'm a bit puzzled by the caching behaviour of QuerySets, when used in
iteration and when called with repr(). According to the documentation,
when a QuerySet is evaluated for the first time, the results are
cached.

Trying this out in the shell, this works as expected for iteration.
However when used with repr(), the QuerySet does not seem to be using
the cache, and I was just wondering if this is the correct behaviour.

I'll just illustrate this with a quick example. The Tag model has a
single field, name.

# starting with no tags
>>> Tag.objects.all()
[]

# create a tag
>>> Tag.objects.create(name='one')
<Tag: one>

# as expected
>>> Tag.objects.all()
[<Tag: one>]

# assigning the QuerySet, as illustrated in documentation
>>> queryset = Tag.objects.all()

# evaluate, by implicitly calling repr()
>>> queryset
[<Tag: one>]

>>> Tag.objects.create(name='two')
<Tag: two>

# expecting queryset to use cache, which does not contain new tag
>>> queryset
[<Tag: one>, <Tag: two>]

# hmm, maybe not??

Any help on clarifying this would be greatly appreciated!

David

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to