From 12c49c75fbd04cfe81808ef300fcb0858d92c7b7 Mon Sep 17 00:00:00 2001 From: Diggory Blake Date: Thu, 23 Mar 2017 14:43:56 +0000 Subject: [PATCH 1/3] Handle BaseExceptions --- flask/app.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flask/app.py b/flask/app.py index 942992dc..1404e17e 100644 --- a/flask/app.py +++ b/flask/app.py @@ -1983,6 +1983,9 @@ class Flask(_PackageBoundObject): except Exception as e: error = e response = self.handle_exception(e) + except: + error = sys.exc_info()[1] + raise return response(environ, start_response) finally: if self.should_ignore_error(error): From d0e2e7b66c2f0a2192ce4b1b54e118345acf7f6e Mon Sep 17 00:00:00 2001 From: Diggory Blake Date: Thu, 23 Mar 2017 16:15:00 +0000 Subject: [PATCH 2/3] Add test and changes --- CHANGES | 15 +++++++++++++++ tests/test_basic.py | 20 ++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/CHANGES b/CHANGES index 03194421..dbb5947a 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,21 @@ Flask Changelog Here you can see the full list of changes between each Flask release. +Version 0.13 +------------ + +Major release, unreleased + +- Make `app.run()` into a noop if a Flask application is run from the + development server on the command line. This avoids some behavior that + was confusing to debug for newcomers. +- Change default configuration `JSONIFY_PRETTYPRINT_REGULAR=False`. jsonify() + method returns compressed response by default, and pretty response in + debug mode. +- Call `ctx.auto_pop` with the exception object instead of `None`, in the + event that a `BaseException` such as `KeyboardInterrupt` is raised in a + request handler. + Version 0.12.1 -------------- diff --git a/tests/test_basic.py b/tests/test_basic.py index be3d5edd..8556268a 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -791,6 +791,26 @@ def test_error_handling_processing(): assert resp.data == b'internal server error' +def test_baseexception_error_handling(): + app = flask.Flask(__name__) + app.config['LOGGER_HANDLER_POLICY'] = 'never' + + @app.route('/') + def broken_func(): + raise KeyboardInterrupt() + + with app.test_client() as c: + try: + c.get('/') + raise AssertionError("KeyboardInterrupt should have been raised") + except KeyboardInterrupt: + pass + + ctx = flask._request_ctx_stack.top + assert ctx.preserved + assert type(ctx._preserved_exc) is KeyboardInterrupt + + def test_before_request_and_routing_errors(): app = flask.Flask(__name__) From 6f7847e3c488fccbfd8c8880683cfe8ae8bdcdc3 Mon Sep 17 00:00:00 2001 From: Diggory Blake Date: Thu, 23 Mar 2017 17:51:45 +0000 Subject: [PATCH 3/3] Make test more idiomatic --- tests/test_basic.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/test_basic.py b/tests/test_basic.py index 8556268a..c5ec9f5c 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -800,11 +800,8 @@ def test_baseexception_error_handling(): raise KeyboardInterrupt() with app.test_client() as c: - try: + with pytest.raises(KeyboardInterrupt): c.get('/') - raise AssertionError("KeyboardInterrupt should have been raised") - except KeyboardInterrupt: - pass ctx = flask._request_ctx_stack.top assert ctx.preserved