﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20075	Cache session test fails when using a cache other than LocMemCache	Martin Larente	nobody	"Whenever the `default` cache is set to a different backend than the default LocMemCache, the cache session tests fail. To reproduce it, put this in your settings file:
{{{
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        'LOCATION': '/path/to/your/cache',  # change this to an actual folder on your system
    }
}
}}}

When the tests are run with this non-default cache, we get:
{{{
FAIL: test_non_default_cache (django.contrib.sessions.tests.CacheSessionTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""C:\Users\Ryo\venv\esi-acctman\lib\site-packages\django\test\utils.py"", line 220, in inner
    return test_func(*args, **kwargs)
  File ""C:\Users\Ryo\venv\esi-acctman\lib\site-packages\django\contrib\sessions\tests.py"", line 473, in test_non_default_cache
    self.assertNotEqual(get_cache('sessions').get(self.session.cache_key), None)
AssertionError: None == None
}}}

The reason for this is that, although the test is run with overridden settings that sets LocMemCache as the cache to use for the session backend:
{{{
    @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):
        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)
}}}

The actual session instance (`self.session`) is created in the setup method of `SessionTestsMixin`, which doesn't override these settings. It works with the default cache settings because it just so happens that the default cache system is also the one used in the test, but as soon as the `default` cache backend is changed, the test fails."	Bug	closed	contrib.sessions	1.5	Normal	fixed			Accepted	0	0	0	0	0	0
