Opened 5 years ago

Closed 5 years ago

#21000 closed Bug (fixed)

Session cached_db backend doesn't use SESSION_CACHE_ALIAS

Reported by: CHI Cheng Owned by: nobody
Component: contrib.sessions Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


cached_db always use default cache backend

Change History (4)

comment:2 Changed 5 years ago by Aymeric Augustin

Needs documentation: set
Needs tests: set
Triage Stage: UnreviewedAccepted

Patch looks OK, it would be nice to add tests (or a strong rationale as to why they're impossible to write; I can't remember what support for testing multiple caches we currently have).

This is worth mentioning in the release notes too.

comment:3 Changed 5 years ago by CHI Cheng

Added a small test.

A weird thing: the previous code could also pass this test: (copied from CacheSessionTests in contrib/sessions/

        'default': {
            'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
        'sessions': {
            'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    }, SESSION_CACHE_ALIAS='sessions')
    def test_non_default_cache(self):
        # Re-initalize the session backend to make use of overridden settings.
        self.session = self.backend()
        self.assertEqual(get_cache('default').get(self.session.cache_key), None)
        self.assertNotEqual(get_cache('sessions').get(self.session.cache_key), None)  # Should fail here as previous code always use `default` cache

comment:4 Changed 5 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In ed9cd4fd8b425ab5010b27aefc7ef6e50d55fb54:

Fixed #21000 -- Made cached_db session backend respect SESSION_CACHE_ALIAS

Note: See TracTickets for help on using tickets.
Back to Top