Skip to content
Myr

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

4 files+44 added−2 removed

modified:docs/upgrading.rst+11 added
17 unmodified lines
18installation, make sure to pass it the ``-U`` parameter::1920 $ easy_install -U Flask2122Version 0.623-----------2425Flask 0.6 comes with a backwards incompatible change which affects the26order of after-request handlers. Previously they were called in the order27of the registration, now they are called in reverse order. This change28was made so that Flask behaves more like people expected it to work and29how other systems handle request pre- and postprocessing. If you30dependend on the order of execution of post-request functions, be sure to31change the order.3233Version 0.534-----------3536Flask 0.5 is the first release that comes as a Python package instead of a
68 unmodified lines
modified:flask/app.py+6 added-2 removed
705 unmodified lines
706 """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.709710 .. versionchanged:: 0.5711 As of Flask 0.5 the functions registered for after request712 execution are called in reverse order of registration.713714 :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 lines
720 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 lines
modified:tests/flask_tests.py+24 added
316 unmodified lines
317 assert rv.status_code == 500318 assert 'Internal Server Error' in rv.data319 assert len(called) == 1320321 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]344345 def test_error_handling(self):346 app = flask.Flask(__name__)347 @app.errorhandler(404)348 def not_found(e):
636 unmodified lines
modified:CHANGES+3 added
6 unmodified lines
7-----------89Release date to be announced, codename to be decided.1011- after request functions are now called in reverse order of12 registration.1314Version 0.5.115-------------1617Bugfix Release, released on July 6th 2010
97 unmodified lines