Opened 6 years ago

Closed 6 years ago

#19147 closed Bug (invalid)

session.session_key is None for signed_cookies sessions on first request

Reported by: rwmcfa1 Owned by: nobody
Component: contrib.sessions Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


SessionBase defines:

def _get_session_key(self):

return self._session_key

and sets up a property, session_key to use it

session_key = property(_get_session_key)

signed_cookies.SessionStore overrides _get_session_key and comments as to why.

the problem is that the property, session_key calls the parent class method (SessionBase) rather than the signed_cookies.SessionStore version. that's not destructive in this case since the parent class one just returns the current value, but it causes things that look for the session_key (request.session.session_key) to get the wrong answer (None) on the first request. subsequent requests will see the correct value.

fix, though maybe less than ideal, is to re-define the property at the bottom of signed_cookies so that the descendant class's method will be called.

session_key = property(_get_session_key)

Change History (1)

comment:1 Changed 6 years ago by Aymeric Augustin

Resolution: invalid
Status: newclosed

By design you can't access the session key until you save the session.

I've explained why in this discussion. does self._session_key = self._get_session_key(), which resolves your problem.

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