diff --git a/CHANGES b/CHANGES index b33c3795..1727a794 100644 --- a/CHANGES +++ b/CHANGES @@ -91,6 +91,8 @@ Version 0.10.2 - Changed logic of before first request handlers to flip the flag after invoking. This will allow some uses that are potentially dangerous but should probably be permitted. +- Fixed Python 3 bug when a handler from `app.url_build_error_handlers` + reraises the `BuildError`. Version 0.10.1 -------------- diff --git a/flask/app.py b/flask/app.py index f0a8b69b..186e6e29 100644 --- a/flask/app.py +++ b/flask/app.py @@ -1769,8 +1769,9 @@ class Flask(_PackageBoundObject): rv = handler(error, endpoint, values) if rv is not None: return rv - except BuildError as error: - pass + except BuildError as e: + # make error available outside except block (py3) + error = e # At this point we want to reraise the exception. If the error is # still the same one we can reraise it with the original traceback, diff --git a/tests/test_basic.py b/tests/test_basic.py index 695e346e..d22e9e5b 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -1069,6 +1069,18 @@ def test_build_error_handler(): assert flask.url_for('spam') == '/test_handler/' +def test_build_error_handler_reraise(): + app = flask.Flask(__name__) + + # Test a custom handler which reraises the BuildError + def handler_raises_build_error(error, endpoint, values): + raise error + app.url_build_error_handlers.append(handler_raises_build_error) + + with app.test_request_context(): + pytest.raises(BuildError, flask.url_for, 'not.existing') + + def test_custom_converters(): from werkzeug.routing import BaseConverter