From 5faf745999caa3d2588979ae1262cc28652c21a5 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 3 Apr 2016 15:09:10 -0700 Subject: [PATCH] Refs #21608 -- Fixed incorrect cache key in cache session backend's save(). The bug was introduced commit 3389c5ea229884a1943873fe7e7ffc2800cefc22. --- django/contrib/sessions/backends/cache.py | 2 +- tests/sessions_tests/tests.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/django/contrib/sessions/backends/cache.py b/django/contrib/sessions/backends/cache.py index 602596073d..d50a17cdd8 100644 --- a/django/contrib/sessions/backends/cache.py +++ b/django/contrib/sessions/backends/cache.py @@ -57,7 +57,7 @@ class SessionStore(SessionBase): return self.create() if must_create: func = self._cache.add - elif self._cache.get(self.session_key) is not None: + elif self._cache.get(self.cache_key) is not None: func = self._cache.set else: raise UpdateError diff --git a/tests/sessions_tests/tests.py b/tests/sessions_tests/tests.py index bb8ca2b635..6a8a7ee96b 100644 --- a/tests/sessions_tests/tests.py +++ b/tests/sessions_tests/tests.py @@ -613,6 +613,12 @@ class CacheSessionTests(SessionTestsMixin, unittest.TestCase): self.assertEqual(caches['default'].get(self.session.cache_key), None) self.assertNotEqual(caches['sessions'].get(self.session.cache_key), None) + def test_create_and_save(self): + self.session = self.backend() + self.session.create() + self.session.save() + self.assertIsNotNone(caches['default'].get(self.session.cache_key)) + class SessionMiddlewareTests(TestCase):