Opened 19 years ago

Closed 19 years ago

#1095 closed defect (fixed)

[patch] SESSION_SAVE_EVERY_REQUEST causes errors when you hit the server with a redirect

Reported by: Ian@… Owned by: Adrian Holovaty
Component: Core (Other) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

i've been playing a bit with the session cookie, and noticed that if you don't have a initial cookie and one isn't set by the request (ie..it's a redirect) then you will get a attribute error as there is no request.session object

fix:

Index: sessions.py
===================================================================
--- sessions.py (revision 1749)
+++ sessions.py (working copy)
@@ -68,10 +68,13 @@
         except AttributeError:
             modified = False
         if modified or SESSION_SAVE_EVERY_REQUEST:
-            session_key = request.session.session_key or sessions.get_new_session_key()
-            new_session = sessions.save(session_key, request.session._session,
-                datetime.datetime.now() + datetime.timedelta(seconds=SESSION_COOKIE_AGE))
-            expires = datetime.datetime.strftime(datetime.datetime.utcnow() + datetime.timedelta(seconds=SESSION_COOKIE_AGE), "%a, %d-%b-%Y %H:%M:%S GMT")
-            response.set_cookie(SESSION_COOKIE_NAME, session_key,
-                max_age=SESSION_COOKIE_AGE, expires=expires, domain=SESSION_COOKIE_DOMAIN)
+            try:
+                session_key = request.session.session_key or sessions.get_new_session_key()
+                new_session = sessions.save(session_key, request.session._session,
+                    datetime.datetime.now() + datetime.timedelta(seconds=SESSION_COOKIE_AGE))
+                expires = datetime.datetime.strftime(datetime.datetime.utcnow() + datetime.timedelta(seconds=SESSION_COOKIE_AGE), "%a, %d-%b-%Y %H:%M:%S GMT")
+                response.set_cookie(SESSION_COOKIE_NAME, session_key,
+                    max_age=SESSION_COOKIE_AGE, expires=expires, domain=SESSION_COOKIE_DOMAIN)
+            except AttributeError:
+                pass
         return response

Change History (2)

comment:1 by Adrian Holovaty, 19 years ago

Summary: SESSION_SAVE_EVERY_REQUEST causes errors when you hit the server with a redirect[patch] SESSION_SAVE_EVERY_REQUEST causes errors when you hit the server with a redirect

comment:2 by Malcolm Tredinnick, 19 years ago

Resolution: fixed
Status: newclosed

This was fixed somewhere between [1866] and [1979].

Note: See TracTickets for help on using tickets.
Back to Top