diff --git a/docs/config.rst b/docs/config.rst index aedaae7d..dc761657 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -240,6 +240,7 @@ your configuration files. However here a list of good recommendations: and exports the development configuration for you. - Use a tool like `fabric`_ in production to push code and configurations separately to the production server(s). For some - details about how to do that, head over to the :ref:`deploy` pattern. + details about how to do that, head over to the + :ref:`fabric-deployment` pattern. .. _fabric: http://fabfile.org/ diff --git a/docs/extensiondev.rst b/docs/extensiondev.rst index 2c79c6ab..6b407b34 100644 --- a/docs/extensiondev.rst +++ b/docs/extensiondev.rst @@ -290,6 +290,29 @@ and bind their app to the extension in another file:: manager.init_app(app) +End-Of-Request Behavior +----------------------- + +Due to the change in Flask 0.7 regarding functions that are run at the end +of the request your extension will have to be extra careful there if it +wants to continue to support older versions of Flask. The following +pattern is a good way to support both:: + + def close_connection(response): + ctx = _request_ctx_stack.top + ctx.sqlite3_db.close() + return response + + if hasattr(app, 'teardown_request'): + app.teardown_request(close_connection) + else: + app.after_request(close_connection) + +Strictly speaking the above code is wrong, because teardown functions are +passed the exception and typically don't return anything. However because +the return value is discarded this will just work assuming that the code +in between does not touch the passed parameter. + Learn from Others ----------------- diff --git a/flask/app.py b/flask/app.py index c1bcc340..36f91128 100644 --- a/flask/app.py +++ b/flask/app.py @@ -793,10 +793,21 @@ class Flask(_PackageBoundObject): .. versionadded: 0.3 """ + exc_type, exc_value, tb = sys.exc_info() + got_request_exception.send(self, exception=e) handler = self.error_handlers.get(500) + if self.propagate_exceptions: - raise + # if we want to repropagate the exception, we can attempt to + # raise it with the whole traceback in case we can do that + # (the function was actually called from the except part) + # otherwise, we just raise the error again + if exc_value is e: + raise exc_type, exc_value, tb + else: + raise e + self.logger.exception('Exception on %s [%s]' % ( request.path, request.method