Opened 13 years ago

Closed 13 years ago

#17694 closed Uncategorized (duplicate)

Docs incorrectly explain QuerySet caching

Reported by: anonymous Owned by: nobody
Component: Uncategorized Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

https://docs.djangoproject.com/en/dev/topics/db/queries/#caching-and-querysets

The documentation states that the query is re-evaluated with each new QuerySet, however, according to the following stackoverflow entry, this is not the case, and different QuerySet objects are returning a cached value.

http://stackoverflow.com/questions/3346124/how-do-i-force-django-to-ignore-any-caches-and-reload-data

>>> MyModel.objects.count()
885
# (Here I added some more data from another process.)
>>> MyModel.objects.count()
885

Change History (1)

comment:1 by Carl Meyer, 13 years ago

Resolution: duplicate
Status: newclosed

Thanks for the report!

The behavior shown in the linked SO question has nothing to do with Django QuerySet caches; it's about MySQL's default transaction isolation level of REPEATABLE READ (whereas most other databases default to READ COMMITTED). The docs on QuerySet caching are correct; those different querysets are not using the queryset cache, they are repeating the database query, and it is MySQL that is returning the same data in response to each query, because you're still in the same transaction.

It's not clear what, if anything, Django ought to do about this - but whatever we might do about it, it's being tracked in #13906 already. Closing as duplicate.

Note: See TracTickets for help on using tickets.
Back to Top