forked from orbit-oss/flask
fix UnboundLocalError in handle_url_build_error
- caused by changes in the execution model of python 3 where the alias of an except clause is cleared on exit of the except
This commit is contained in:
parent
d734baf176
commit
5da31f8af3
2 changed files with 14 additions and 2 deletions
|
|
@ -1631,8 +1631,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,
|
||||
|
|
|
|||
|
|
@ -772,6 +772,17 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|||
with app.test_request_context():
|
||||
self.assert_equal(flask.url_for('spam'), '/test_handler/')
|
||||
|
||||
def test_build_error_handler_reraise(self):
|
||||
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():
|
||||
self.assertRaises(BuildError, flask.url_for, 'not.existing')
|
||||
|
||||
def test_custom_converters(self):
|
||||
from werkzeug.routing import BaseConverter
|
||||
class ListConverter(BaseConverter):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue