diff --git a/django/contrib/sessions/backends/cache.py b/django/contrib/sessions/backends/cache.py index 7c3eecd425..467d5f1265 100644 --- a/django/contrib/sessions/backends/cache.py +++ b/django/contrib/sessions/backends/cache.py @@ -19,10 +19,9 @@ class SessionStore(SessionBase): def load(self): try: session_data = self._cache.get(self.cache_key, None) - except Exception, e: - e_type = str(type(e)) - if e_type != "": - raise e + except Exception: + # Some backends (e.g. memcache) raise an exception on invalid + # cache keys. If this happens, reset the session. See #17810. session_data = None if session_data is not None: return session_data diff --git a/django/contrib/sessions/backends/cached_db.py b/django/contrib/sessions/backends/cached_db.py index db0d3515b1..ff6076df77 100644 --- a/django/contrib/sessions/backends/cached_db.py +++ b/django/contrib/sessions/backends/cached_db.py @@ -24,10 +24,9 @@ class SessionStore(DBStore): def load(self): try: data = cache.get(self.cache_key, None) - except Exception, e: - e_type = str(type(e)) - if e_type != "": - raise e + except Exception: + # Some backends (e.g. memcache) raise an exception on invalid + # cache keys. If this happens, reset the session. See #17810. data = None if data is None: data = super(SessionStore, self).load()