Skip to content
Myr

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

3 files+53 added−1 removed

modified:docs/upgrading.rst+47 added
20 unmodified lines
2122Version 0.723-----------2425The following backwards incompatible changes exist from 0.6 to 0.72627Bug in Request Locals28`````````````````````2930Due to a bug in earlier implementations the request local proxies now31raise a :exc:`RuntimeError` instead of an :exc:`AttributeError` when they32are unbound. If you caught these exceptions with :exc:`AttributeError`33before, you should catch them with :exc:`RuntimeError` now.
14 unmodified lines
48New code::4950 return send_file(my_file_object, add_etags=False)5152.. _upgrading-to-new-teardown-handling:5354Upgrading to new Teardown Handling55``````````````````````````````````5657We streamlined the behavior of the callbacks for request handling. For58things that modify the response the :meth:`~flask.Flask.after_request`59decorators continue to work as expected, but for things that absolutely60must happen at the end of request we introduced the new61:meth:`~flask.Flask.teardown_request` decorator. Unfortunately that62change also made after-request work differently under error conditions.63It's not consistently skipped if exceptions happen whereas previously it64might have been called twice to ensure it is executed at the end of the65request.6667If you have database connection code that looks like this::6869 @app.after_request70 def after_request(response):71 g.db.close()72 return response7374You are now encouraged to use this instead::7576 @app.teardown_request77 def after_request(exception):78 g.db.close()7980On the upside this change greatly improves the internal code flow and81makes it easier to customize the dispatching and error handling. This82makes it now a lot easier to write unit tests as you can prevent closing83down of database connections for a while. You can take advantage of the84fact that the teardown callbacks are called when the response context is85removed from the stack so a test can query the database after request86handling::8788 with app.test_client() as client:89 resp = client.get('/')90 # g.db is still bound if there is such a thing9192 # and here it's gone9394Version 0.695-----------9697Flask 0.6 comes with a backwards incompatible change which affects the
87 unmodified lines
modified:flask/app.py+2 added
829 unmodified lines
830 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.834835 .. versionadded:: 0.7836 """837 try:838 request_started.send(self)839 rv = self.preprocess_request()
217 unmodified lines
modified:CHANGES+4 added-1 removed
36 unmodified lines
37 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.5152Version 0.6.153-------------54
159 unmodified lines