From 962defed0adab6144464337a9cad44a4323ae3de Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Thu, 25 Mar 2010 10:29:06 +0000 Subject: [PATCH] Fixed #13200 -- Updated the DB session backend to make full use of routers, deprecating the need for the SESSION_DB_ALIAS setting. Thanks to rokclimb15 for the report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12844 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/sessions/backends/db.py | 10 +++++----- docs/ref/settings.txt | 12 ------------ docs/topics/http/sessions.txt | 7 ------- 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/django/contrib/sessions/backends/db.py b/django/contrib/sessions/backends/db.py index 8a53125095..3328cc8cb7 100644 --- a/django/contrib/sessions/backends/db.py +++ b/django/contrib/sessions/backends/db.py @@ -3,7 +3,7 @@ from django.conf import settings 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, DEFAULT_DB_ALIAS +from django.db import IntegrityError, transaction, router from django.utils.encoding import force_unicode class SessionStore(SessionBase): @@ -11,7 +11,6 @@ class SessionStore(SessionBase): Implements database session store. """ def __init__(self, session_key=None): - self.using = getattr(settings, "SESSION_DB_ALIAS", DEFAULT_DB_ALIAS) super(SessionStore, self).__init__(session_key) def load(self): @@ -58,12 +57,13 @@ class SessionStore(SessionBase): session_data = self.encode(self._get_session(no_load=must_create)), expire_date = self.get_expiry_date() ) - sid = transaction.savepoint(using=self.using) + using = router.db_for_write(Session, instance=obj) + sid = transaction.savepoint(using=using) try: - obj.save(force_insert=must_create) + obj.save(force_insert=must_create, using=using) except IntegrityError: if must_create: - transaction.savepoint_rollback(sid, using=self.using) + transaction.savepoint_rollback(sid, using=using) raise CreateError raise diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt index 7fda207d5b..f8d76080e2 100644 --- a/docs/ref/settings.txt +++ b/docs/ref/settings.txt @@ -1299,18 +1299,6 @@ See the :ref:`topics-http-sessions`. .. setting:: SESSION_EXPIRE_AT_BROWSER_CLOSE -SESSION_DB_ALIAS ----------------- - -.. versionadded:: 1.2 - -Default: ``None`` - -If you're using database-backed session storage, this selects the database -alias that will be used to store session data. By default, Django will use -the ``default`` database, but you can store session data on any database -you choose. - SESSION_EXPIRE_AT_BROWSER_CLOSE ------------------------------- diff --git a/docs/topics/http/sessions.txt b/docs/topics/http/sessions.txt index 3354eb7f24..bce5e1b2f0 100644 --- a/docs/topics/http/sessions.txt +++ b/docs/topics/http/sessions.txt @@ -44,16 +44,9 @@ Using database-backed sessions If you want to use a database-backed session, you need to add ``'django.contrib.sessions'`` to your ``INSTALLED_APPS`` setting. -If you want to store your session data on a database other than ``default`` -alias, you should set the :setting:`SESSION_DB_ALIAS` setting. - Once you have configured your installation, run ``manage.py syncdb`` to install the single database table that stores session data. -.. versionadded:: 1.2 - The :setting:`SESSION_DB_ALIAS` setting was added in Django 1.2. It - is not required in earlier versions. - Using cached sessions ---------------------