Skip to content

Commit 952a6c8

Browse files
Werkzeug should not block propagated exceptions from Flask
1 parent f17e606 commit 952a6c8

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

flask/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ def run(self, host=None, port=None, debug=None, **options):
833833
self.debug = bool(debug)
834834
options.setdefault('use_reloader', self.debug)
835835
options.setdefault('use_debugger', self.debug)
836+
options.setdefault('passthrough_errors', True)
836837
try:
837838
run_simple(host, port, self, **options)
838839
finally:

flask/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ def run_command(info, host, port, reload, debugger, eager_loading,
422422
print(' * Forcing debug %s' % (info.debug and 'on' or 'off'))
423423

424424
run_simple(host, port, app, use_reloader=reload,
425-
use_debugger=debugger, threaded=with_threads)
425+
use_debugger=debugger, threaded=with_threads,
426+
passthrough_errors=True)
426427

427428

428429
@click.command('shell', short_help='Runs a shell in the app context.')

tests/test_basic.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,26 @@ def index():
12221222
t.join()
12231223

12241224

1225+
@pytest.mark.parametrize('debug', [True, False])
1226+
@pytest.mark.parametrize('use_debugger', [True, False])
1227+
@pytest.mark.parametrize('use_reloader', [True, False])
1228+
@pytest.mark.parametrize('propagate_exceptions', [None, True, False])
1229+
def test_werkzeug_passthrough_errors(monkeypatch, debug, use_debugger,
1230+
use_reloader, propagate_exceptions):
1231+
rv = {}
1232+
1233+
# Mocks werkzeug.serving.run_simple method
1234+
def run_simple_mock(*args, **kwargs):
1235+
rv['passthrough_errors'] = kwargs.get('passthrough_errors')
1236+
1237+
app = flask.Flask(__name__)
1238+
monkeypatch.setattr(werkzeug.serving, 'run_simple', run_simple_mock)
1239+
app.config['PROPAGATE_EXCEPTIONS'] = propagate_exceptions
1240+
app.run(debug=debug, use_debugger=use_debugger, use_reloader=use_reloader)
1241+
# make sure werkzeug always passes errors through
1242+
assert rv['passthrough_errors']
1243+
1244+
12251245
def test_max_content_length():
12261246
app = flask.Flask(__name__)
12271247
app.config['MAX_CONTENT_LENGTH'] = 64

0 commit comments

Comments
 (0)