Jim Geist
jimge at rodentia.net
Thu Apr 24 01:05:07 EDT 2008
I was trying to figure out why my session data was getting lost, and I came across some interesting behavior. Code snippet: # processing POST data from a form if login_success(): session["userid"] = userid psp.redirect("loggedin.psp") in loggedin.psp userid = session["userid"] # Whoops! KeyError! Under normal circumstances, the psp run method does a session save automatically, but it wasn't happening here. Digging through the source reveals that this is because redirect raises apache.SERVER_RETURN, and the run code doesn't call session.save() if the page raises any exceptions. I can see in the general case that an argument could be made for not saving session data in the exception case; if an exception makes it back into psp, then something has probably gone wrong with page processing. But in this case, doing the save seems like desired behavior, otherwise code like the above, which seems reasonable, silently has different behavior from the normal case. The fact that the save isn't done is a byproduct of redirect internally using an exception to implement its early exit behavior, which isn't obvious from the interface level. So, feature or bug? -- Jim
|