Opened 8 years ago
Last modified 6 years ago
#28094 new Cleanup/optimization
Document how @override_settings(CACHES=...) can work with class-based views
Reported by: | R3turnz | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.11 |
Severity: | Normal | Keywords: | |
Cc: | Kevin Graves | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The following should override the CACHES setting during tests:
@method_decorator(cache_page(60 * 5), name='dispatch') class IndexView(generic.ListView): if ENABLE_CACHING: CACHES = get_cache() else: CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.dummy.DummyCache', } } @override_settings(CACHES={'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}}) class IndexViewTests(TestCase):
The setting also seems to be correctly overriden, (django.conf.settings contains dummy cache) but I encounter following problems:
- The context of the response is always None.
- Test which formerly passed now fail and view functions are not called.
All problems disappear when I disable caching manually!
This leads me to the assumption that the views are stilled cached.
The documentation says that overriding the cache should be possible and I am not using sessions framwork.
I do not have enough knowledge of the architecture of django to do further debugging.
Change History (5)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
I agree with you that this could be the problem, but how do reinitialize class based views?
comment:3 by , 8 years ago
Component: | Testing framework → Documentation |
---|---|
Summary: | Cache settings override does not work properly → Document how @override_settings(CACHES=...) can work with class-based views |
Type: | Bug → Cleanup/optimization |
I'm not sure if there's an elegant way for this to work.
comment:4 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:5 by , 6 years ago
Cc: | added |
---|
I suspect this is not a bug but that you'll have to reinitialize the class-based view after overriding the
CACHES
setting since it's already been initialized with the original settings values.If that's correct, perhaps the documentation could be clarified.