Reverse order of execution of post-request handlers. This fixes #82
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 f1a6fbe · Browse files · 4 files·+44 added−2 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+44 added−2 removed
- tests:+24 added−0 removed
- other:+20 added−2 removed
Provenance
- Commit
d12d732- Tree
b515a1b- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
f1a6fbe
4 files changed+44 added−2 removed
modified:docs/upgrading.rst+11 added
17 unmodified lines18 installation, make sure to pass it the ``-U`` parameter::19 20 $ easy_install -U Flask21 22+Version 0.623+-----------24+25+Flask 0.6 comes with a backwards incompatible change which affects the26+order of after-request handlers. Previously they were called in the order27+of the registration, now they are called in reverse order. This change28+was made so that Flask behaves more like people expected it to work and29+how other systems handle request pre- and postprocessing. If you30+dependend on the order of execution of post-request functions, be sure to31+change the order.32+33 Version 0.534 -----------35 36 Flask 0.5 is the first release that comes as a Python package instead of a68 unmodified linesmodified:flask/app.py+6 added-2 removed
705 unmodified lines706 """Can be overridden in order to modify the response object707 before it's sent to the WSGI server. By default this will708 call all the :meth:`after_request` decorated functions.709 710+ .. versionchanged:: 0.5711+ As of Flask 0.5 the functions registered for after request712+ execution are called in reverse order of registration.713+714 :param response: a :attr:`response_class` object.715 :return: a new response object or the same, has to be an716 instance of :attr:`response_class`.717 """2 unmodified lines720 if not isinstance(ctx.session, _NullSession):721 self.save_session(ctx.session, response)722 funcs = ()723 if mod and mod in self.after_request_funcs:720- funcs = chain(funcs, self.after_request_funcs[mod])724+ funcs = reversed(self.after_request_funcs[mod])725 if None in self.after_request_funcs:722- funcs = chain(funcs, self.after_request_funcs[None])726+ funcs = chain(funcs, reversed(self.after_request_funcs[None]))727 for handler in funcs:728 response = handler(response)729 return response730 89 unmodified linesmodified:tests/flask_tests.py+24 added
316 unmodified lines317 assert rv.status_code == 500318 assert 'Internal Server Error' in rv.data319 assert len(called) == 1320 321+ def test_before_after_request_order(self):322+ called = []323+ app = flask.Flask(__name__)324+ @app.before_request325+ def before1():326+ called.append(1)327+ @app.before_request328+ def before2():329+ called.append(2)330+ @app.after_request331+ def after1(response):332+ called.append(4)333+ return response334+ @app.after_request335+ def after1(response):336+ called.append(3)337+ return response338+ @app.route('/')339+ def index():340+ return '42'341+ rv = app.test_client().get('/')342+ assert rv.data == '42'343+ assert called == [1, 2, 3, 4]344+345 def test_error_handling(self):346 app = flask.Flask(__name__)347 @app.errorhandler(404)348 def not_found(e):636 unmodified linesmodified:CHANGES+3 added
6 unmodified lines7 -----------8 9 Release date to be announced, codename to be decided.10 11+- after request functions are now called in reverse order of12+ registration.13+14 Version 0.5.115 -------------16 17 Bugfix Release, released on July 6th 201097 unmodified lines