More documentation updates
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent a9fc040 · Browse files · 3 files·+53 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+53 added−1 removed
- other:+53 added−1 removed
Provenance
- Commit
115d31d- Tree
d68081c- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
a9fc040
3 files changed+53 added−1 removed
modified:docs/upgrading.rst+47 added
20 unmodified lines21 22 Version 0.723 -----------24 25+The following backwards incompatible changes exist from 0.6 to 0.726+27+Bug in Request Locals28+`````````````````````29+30 Due to a bug in earlier implementations the request local proxies now31 raise a :exc:`RuntimeError` instead of an :exc:`AttributeError` when they32 are unbound. If you caught these exceptions with :exc:`AttributeError`33 before, you should catch them with :exc:`RuntimeError` now.14 unmodified lines48 New code::49 50 return send_file(my_file_object, add_etags=False)51 52+.. _upgrading-to-new-teardown-handling:53+54+Upgrading to new Teardown Handling55+``````````````````````````````````56+57+We streamlined the behavior of the callbacks for request handling. For58+things that modify the response the :meth:`~flask.Flask.after_request`59+decorators continue to work as expected, but for things that absolutely60+must happen at the end of request we introduced the new61+:meth:`~flask.Flask.teardown_request` decorator. Unfortunately that62+change also made after-request work differently under error conditions.63+It's not consistently skipped if exceptions happen whereas previously it64+might have been called twice to ensure it is executed at the end of the65+request.66+67+If you have database connection code that looks like this::68+69+ @app.after_request70+ def after_request(response):71+ g.db.close()72+ return response73+74+You are now encouraged to use this instead::75+76+ @app.teardown_request77+ def after_request(exception):78+ g.db.close()79+80+On the upside this change greatly improves the internal code flow and81+makes it easier to customize the dispatching and error handling. This82+makes it now a lot easier to write unit tests as you can prevent closing83+down of database connections for a while. You can take advantage of the84+fact that the teardown callbacks are called when the response context is85+removed from the stack so a test can query the database after request86+handling::87+88+ with app.test_client() as client:89+ resp = client.get('/')90+ # g.db is still bound if there is such a thing91+92+ # and here it's gone93+94 Version 0.695 -----------96 97 Flask 0.6 comes with a backwards incompatible change which affects the87 unmodified linesmodified:flask/app.py+2 added
829 unmodified lines830 def full_dispatch_request(self):831 """Dispatches the request and on top of that performs request832 pre and postprocessing as well as HTTP exception catching and833 error handling.834+835+ .. versionadded:: 0.7836 """837 try:838 request_started.send(self)839 rv = self.preprocess_request()217 unmodified linesmodified:CHANGES+4 added-1 removed
36 unmodified lines37 was incorrectly introduced in 0.6.38 - Added `create_jinja_loader` to override the loader creation process.39 - Implemented a silent flag for `config.from_pyfile`.40 - Added `teardown_request` decorator, for functions that should run at the end41- of a request regardless of whether an exception occurred.41+ of a request regardless of whether an exception occurred. Also the behavior42+ for `after_request` was changed. It's now no longer executed when an exception43+ is raised. See :ref:`upgrading-to-new-teardown-handling`44 - Implemented :func:`flask.has_request_context`45 - Added :func:`safe_join`46 - The automatic JSON request data unpacking now looks at the charset47 mimetype parameter.48 - Don't modify the session on :func:`flask.get_flashed_messages` if there49 are no messages in the session.50+- `before_request` handlers are now able to abort requests with errors.51 52 Version 0.6.153 -------------54 159 unmodified lines