From f356a2e52fd0c36045b960412196552944a57888 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Fri, 23 Mar 2012 16:14:46 +0000 Subject: [PATCH] Fixed #17810 (again). Catch session key errors. The previous commit didn't work with PyLibMC. This solution appears to be the best compromise at this point in the 1.4 release cycle. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17797 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/sessions/backends/cache.py | 7 +++---- django/contrib/sessions/backends/cached_db.py | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) 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()