Opened 11 years ago

Closed 11 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: dev
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

Description

cached_db always use default cache backend

Change History (4)

comment:2 by Aymeric Augustin, 11 years ago

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 by CHI Cheng, 11 years ago

Added a small test.

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

    @override_settings(CACHES={
        '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.session.save()
        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 by Tim Graham <timograham@…>, 11 years ago

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