4π
It appears that middleware is not called when you run scripts/management comands which is why you are seeing the difference. This makes sense when reading the documentation on middleware because it processes things like request and views, which donβt exist in a custom script.
I found a way around this, and there is an issue regarding it in the Johnny Cache bitbucket repo. In your script put the following before you do anything with the database:
from johnny.middleware import QueryCacheMiddleware
qcm = QueryCacheMiddleware()
# put the code for you script here
qcm.unpatch()
You can see more on that here:
https://bitbucket.org/jmoiron/johnny-cache/issue/49/offline-caching
and here:
https://bitbucket.org/jmoiron/johnny-cache/issue/50/johhny-cache-not-active-in-management
3π
That is the recommended way from the documentation:
from johnny.cache import enable
enable()
Update:
What I observed, as if your tasks.py files have this in the beginning, you can not disable johnny cache using settings.py anymore.
I have reported the issue: https://github.com/jmoiron/johnny-cache/issues/27
- [Django]-Django transaction using multi-db
- [Django]-AssertEqual fails even though the values are the same in python/django
- [Django]-Starting first Django project errors
- [Django]-Django move data from local to production?
- [Django]-IF statement not working with list difference