Code

Ticket #8314: session-fix.diff

File session-fix.diff, 1.8 KB (added by anonymous, 6 years ago)
Line 
1Index: django/contrib/sessions/backends/base.py
2===================================================================
3--- django/contrib/sessions/backends/base.py    (revision 8340)
4+++ django/contrib/sessions/backends/base.py    (working copy)
5@@ -173,11 +173,14 @@
6         delta = expiry - datetime.now()
7         return delta.days * 86400 + delta.seconds
8 
9-    def get_expiry_date(self):
10+    def get_expiry_date(self, creating=False):
11         """Get session the expiry date (as a datetime object)."""
12-        expiry = self.get('_session_expiry')
13-        if isinstance(expiry, datetime):
14-            return expiry
15+        if creating:
16+            expiry = None
17+        else:
18+            expiry = self.get('_session_expiry')
19+            if isinstance(expiry, datetime):
20+                return expiry
21         if not expiry:   # Checks both None and 0 cases
22             expiry = settings.SESSION_COOKIE_AGE
23         return datetime.now() + timedelta(seconds=expiry)
24Index: django/contrib/sessions/backends/db.py
25===================================================================
26--- django/contrib/sessions/backends/db.py      (revision 8340)
27+++ django/contrib/sessions/backends/db.py      (working copy)
28@@ -47,10 +47,14 @@
29         create a *new* entry (as opposed to possibly updating an existing
30         entry).
31         """
32+        if must_create:
33+            session_data = self.encode({})
34+        else:
35+            session_data = self.encode(self._session)
36         obj = Session(
37             session_key = self.session_key,
38-            session_data = self.encode(self._session),
39-            expire_date = self.get_expiry_date()
40+            session_data = session_data,
41+            expire_date = self.get_expiry_date(creating=True)
42         )
43         sid = transaction.savepoint()
44         try: