Session.cycle_key() throws Exception if the session hasn't been accessed
|Reported by:||adam-iris||Owned by:||Adam Zapletal|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
A common use case I see is that a user changes some content then tries to view their changes on the website, but they get an older, previously-cached page.
Since the page-level cache key uses the session id, my solution is to call
request.session.cycle_key(). To the user this is presented as a "hard reload" -- it clears the session key then redirects back to the current page, the page-level cache will miss and the user will get a newly-generated version.
However, this raised an exception:
'SessionStore' object has no attribute '_session_cache'
Upon inspection, it looks like
SessionBase._session_cache doesn't get initialized except by calling
SessionBase._session. But the
cycle_key() method accesses
_session_cache without ensuring that it's been initialized.
My workaround was to prepend a meaningless access call:
This fixed the exception, but I think the proper fix is for
cycle_key() to initialize (or more carefully check)
Change History (7)
comment:1 Changed 10 months ago by
|Triage Stage:||Unreviewed → Accepted|
|Type:||Uncategorized → Cleanup/optimization|
comment:2 Changed 9 months ago by
|Owner:||changed from nobody to Adam Zapletal|
|Status:||new → assigned|