From 213f294638d353a8763e78e7426ddbea32f0453c Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sat, 23 Aug 2008 22:59:04 +0000 Subject: [PATCH] Avoid a crash when unencoding session data for the db backend. This is required because some configurations of MySQL (with utf8_bin collation) will return bytestring, rather than unicode data, which was causing problems previously. Refs #8340. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8507 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/sessions/backends/db.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/django/contrib/sessions/backends/db.py b/django/contrib/sessions/backends/db.py index 0d68f13e68..85c4a0dd3c 100644 --- a/django/contrib/sessions/backends/db.py +++ b/django/contrib/sessions/backends/db.py @@ -3,6 +3,7 @@ from django.contrib.sessions.models import Session from django.contrib.sessions.backends.base import SessionBase, CreateError from django.core.exceptions import SuspiciousOperation from django.db import IntegrityError, transaction +from django.utils.encoding import force_unicode class SessionStore(SessionBase): """ @@ -14,7 +15,7 @@ class SessionStore(SessionBase): session_key = self.session_key, expire_date__gt=datetime.datetime.now() ) - return self.decode(s.session_data) + return self.decode(force_unicode(s.session_data)) except (Session.DoesNotExist, SuspiciousOperation): self.create() return {}