Opened 7 years ago

Closed 7 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


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.

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

Change History (1)

comment:1 Changed 7 years ago by Carl Meyer

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