From 578e576c31fcd5757c3f4fc2dea7673b3462f575 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 3 May 2017 10:09:28 -0400 Subject: [PATCH] Fixed #28167 -- Fixed cache backend's SessionStore.exists() if session_key is None. --- django/contrib/sessions/backends/cache.py | 2 +- tests/sessions_tests/tests.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/django/contrib/sessions/backends/cache.py b/django/contrib/sessions/backends/cache.py index c0d17ca45a..860d3a46c5 100644 --- a/django/contrib/sessions/backends/cache.py +++ b/django/contrib/sessions/backends/cache.py @@ -67,7 +67,7 @@ class SessionStore(SessionBase): raise CreateError def exists(self, session_key): - return session_key and (self.cache_key_prefix + session_key) in self._cache + return bool(session_key) and (self.cache_key_prefix + session_key) in self._cache def delete(self, session_key=None): if session_key is None: diff --git a/tests/sessions_tests/tests.py b/tests/sessions_tests/tests.py index 552b80daeb..b70df90834 100644 --- a/tests/sessions_tests/tests.py +++ b/tests/sessions_tests/tests.py @@ -348,7 +348,8 @@ class SessionTestsMixin: session = self.backend('someunknownkey') session.load() - self.assertFalse(session.exists(session.session_key)) + self.assertIsNone(session.session_key) + self.assertIs(session.exists(session.session_key), False) # provided unknown key was cycled, not reused self.assertNotEqual(session.session_key, 'someunknownkey')