Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13200 -- Updated the DB session backend to make full use of ro…

…uters, 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
  • Loading branch information...
commit 962defed0adab6144464337a9cad44a4323ae3de 1 parent c62c47e
Russell Keith-Magee authored March 25, 2010
10  django/contrib/sessions/backends/db.py
@@ -3,7 +3,7 @@
3 3
 from django.contrib.sessions.models import Session
4 4
 from django.contrib.sessions.backends.base import SessionBase, CreateError
5 5
 from django.core.exceptions import SuspiciousOperation
6  
-from django.db import IntegrityError, transaction, DEFAULT_DB_ALIAS
  6
+from django.db import IntegrityError, transaction, router
7 7
 from django.utils.encoding import force_unicode
8 8
 
9 9
 class SessionStore(SessionBase):
@@ -11,7 +11,6 @@ class SessionStore(SessionBase):
11 11
     Implements database session store.
12 12
     """
13 13
     def __init__(self, session_key=None):
14  
-        self.using = getattr(settings, "SESSION_DB_ALIAS", DEFAULT_DB_ALIAS)
15 14
         super(SessionStore, self).__init__(session_key)
16 15
 
17 16
     def load(self):
@@ -58,12 +57,13 @@ def save(self, must_create=False):
58 57
             session_data = self.encode(self._get_session(no_load=must_create)),
59 58
             expire_date = self.get_expiry_date()
60 59
         )
61  
-        sid = transaction.savepoint(using=self.using)
  60
+        using = router.db_for_write(Session, instance=obj)
  61
+        sid = transaction.savepoint(using=using)
62 62
         try:
63  
-            obj.save(force_insert=must_create)
  63
+            obj.save(force_insert=must_create, using=using)
64 64
         except IntegrityError:
65 65
             if must_create:
66  
-                transaction.savepoint_rollback(sid, using=self.using)
  66
+                transaction.savepoint_rollback(sid, using=using)
67 67
                 raise CreateError
68 68
             raise
69 69
 
12  docs/ref/settings.txt
@@ -1299,18 +1299,6 @@ See the :ref:`topics-http-sessions`.
1299 1299
 
1300 1300
 .. setting:: SESSION_EXPIRE_AT_BROWSER_CLOSE
1301 1301
 
1302  
-SESSION_DB_ALIAS
1303  
-----------------
1304  
-
1305  
-.. versionadded:: 1.2
1306  
-
1307  
-Default: ``None``
1308  
-
1309  
-If you're using database-backed session storage, this selects the database
1310  
-alias that will be used to store session data. By default, Django will use
1311  
-the ``default`` database, but you can store session data on any database
1312  
-you choose.
1313  
-
1314 1302
 SESSION_EXPIRE_AT_BROWSER_CLOSE
1315 1303
 -------------------------------
1316 1304
 
7  docs/topics/http/sessions.txt
@@ -44,16 +44,9 @@ Using database-backed sessions
44 44
 If you want to use a database-backed session, you need to add
45 45
 ``'django.contrib.sessions'`` to your ``INSTALLED_APPS`` setting.
46 46
 
47  
-If you want to store your session data on a database other than ``default``
48  
-alias, you should set the :setting:`SESSION_DB_ALIAS` setting.
49  
-
50 47
 Once you have configured your installation, run ``manage.py syncdb``
51 48
 to install the single database table that stores session data.
52 49
 
53  
-.. versionadded:: 1.2
54  
-   The :setting:`SESSION_DB_ALIAS` setting was added in Django 1.2. It
55  
-   is not required in earlier versions.
56  
-
57 50
 Using cached sessions
58 51
 ---------------------
59 52
 

0 notes on commit 962defe

Please sign in to comment.
Something went wrong with that request. Please try again.