flask icon indicating copy to clipboard operation
flask copied to clipboard

after_request behavior regarding exceptions

Open mitsuhiko opened this issue 15 years ago • 5 comments

after_request is not executed if an exception happens in debug mode. This is annoying for databases because it requires that you restart the server to tear down the connection. Sometimes that's what you want, otherwise not. The original intention was that you want to continue having the transaction in the interactive debugger.

Generally however we need a separate decorator that always executes after request, even if an exception happened. Signals are one option, if that is what we want we should document it better. I would prefer a separate decorator however.

Related feedback issues:

  • http://feedback.flask.pocoo.org/message/108
  • http://feedback.flask.pocoo.org/message/76

mitsuhiko avatar Feb 17 '11 21:02 mitsuhiko

The current behavior leaves uncommitted transactions around, which can then be committed by subsequent requests. That's really confusing and unexpected behavior, at least for me. On the other hand, I do see the value in keeping the transaction around for the debugger.

I'm not too familiar with the deep internals, so this might not make any sense, but would it be possible to remove the thread in which the exception occurred from the thread pool (and replace it with a new one), but keep that thread alive to run the debugger in? That way, you don't have to execute the after_request functions and kill the DB transaction, but the transaction won't randomly pop up in subsequent requests.

leifkb avatar Mar 10 '11 19:03 leifkb

brainsik and I are working on this.

glyphobet avatar Mar 14 '11 05:03 glyphobet

fixed in SHA: 04e70bd5c7bd80696eabaea11afd9080d874f859

glyphobet avatar Mar 14 '11 19:03 glyphobet

Please close.

rduplain avatar Mar 14 '11 20:03 rduplain

Done.

mitsuhiko avatar Mar 14 '11 20:03 mitsuhiko