Opened 3 years ago

Last modified 21 months 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


The following should override the CACHES setting during tests:

@method_decorator(cache_page(60 * 5), name='dispatch')
class IndexView(generic.ListView):

    CACHES = get_cache()
    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 Changed 3 years ago by Tim Graham

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.

comment:2 Changed 3 years ago by R3turnz

I agree with you that this could be the problem, but how do reinitialize class based views?

Last edited 3 years ago by R3turnz (previous) (diff)

comment:3 Changed 3 years ago by Tim Graham

Component: Testing frameworkDocumentation
Summary: Cache settings override does not work properlyDocument how @override_settings(CACHES=...) can work with class-based views
Type: BugCleanup/optimization

I'm not sure if there's an elegant way for this to work.

comment:4 Changed 3 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:5 Changed 21 months ago by Kevin Graves

Cc: Kevin Graves added
Note: See TracTickets for help on using tickets.
Back to Top