python - django: don't log out when there is an error in view with `request.session.set_exipry` -
i'm developing app django, , every time have error when rendering view or template, session gets logged out. ends being pretty annoying. how disable 'feature'? note don't logged out if there's error when code loaded/parsed (e.g. if decorator on view fails), if there's error within view.
edit: tested , yes, raise exception
in view cause this.
all views wrapped decorator, which, among other things, does:
def needs_base_index_dict(func): def wrapper(request, *args, **kwargs): request.session.set_expiry(30*60) #...
if comment out set_expiry
line, don't behavior. when fix errors, still logged in. if line not commented out, error in view - including raise exception()
- logs session out.
django writes session database everytime there change it. since updating session state in view decorator, means there should session write db.
however, if on database transaction management when view fails database write gets rolled back. session cookie expire time has been updated on browser. means browser session , session stored on server no longer match. inconsistency leads session being dropped , being logged out.
this explains why works alright when comment out line.
if use django dev server should able see queries in console. see if session update query running when error occurs. if not, you'll know why getting logged out :)
this desired behavior if want disable in debug environment, add check debug above relevant line in decorator. alternatively, disable transaction management (not recommended).
Comments
Post a Comment