Populating settings.CACHES based on settings.CACHE_BACKEND can fail
|Reported by:||Jeremy Dunck||Owned by:||nobody|
|Component:||Core (Cache system)||Version:||1.3|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I'm fairly sure this will be WONTFIX'd but I wanted to note this failure case in case it helps others.
If django.core.cache is imported before settings finish loading, it is possible that settings.CACHE_BACKEND will not yet be set, so that forward-compatibility patching proceeds incorrectly -- using locmem rather than whatever may have been declared later.
In my case, I ran into this with the fairly-common pattern of 2 settings files a.py and b.py, where b.py imports * from a. A side-effect of importing a was that django.core.cache got imported.
The final config is defined with CACHE_BACKEND = "dummy://", but CACHES ended up with default engine of "locmem://".
Here's the code that patches CACHES from CACHE_BACKEND (if it's there):
Perhaps a better option would be to make the patching lazier...