Opened 7 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 Tim Graham, 7 years ago

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 by R3turnz, 7 years ago

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

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

comment:3 by Tim Graham, 7 years ago

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 by Tim Graham, 7 years ago

Triage Stage: UnreviewedAccepted

comment:5 by Kevin Graves, 6 years ago

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