Skip to content
Myr

Werkzeug should not block propagated exceptions from Flask

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Miguel Grinberg · committed by Miguel Grinberg · parent f17e606 · Browse files · 3 files+23 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+23 added−1 removed

  • tests:+20 added−0 removed
  • other:+3 added−1 removed

3 files+23 added−1 removed

modified:flask/app.py+1 added
831 unmodified lines
832 if debug is not None:833 self.debug = bool(debug)834 options.setdefault('use_reloader', self.debug)835 options.setdefault('use_debugger', self.debug)836 options.setdefault('passthrough_errors', True)837 try:838 run_simple(host, port, self, **options)839 finally:840 # reset the first request information if the development server
1146 unmodified lines
modified:flask/cli.py+2 added-1 removed
420 unmodified lines
421 if info.debug is not None:422 print(' * Forcing debug %s' % (info.debug and 'on' or 'off'))423424 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)427428429@click.command('shell', short_help='Runs a shell in the app context.')430@with_appcontext
69 unmodified lines
modified:tests/test_basic.py+20 added
1220 unmodified lines
1221 t.start()1222 t.join()122312241225@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])1229def test_werkzeug_passthrough_errors(monkeypatch, debug, use_debugger,1230 use_reloader, propagate_exceptions):1231 rv = {}12321233 # Mocks werkzeug.serving.run_simple method1234 def run_simple_mock(*args, **kwargs):1235 rv['passthrough_errors'] = kwargs.get('passthrough_errors')12361237 app = flask.Flask(__name__)1238 monkeypatch.setattr(werkzeug.serving, 'run_simple', run_simple_mock)1239 app.config['PROPAGATE_EXCEPTIONS'] = propagate_exceptions1240 app.run(debug=debug, use_debugger=use_debugger, use_reloader=use_reloader)1241 # make sure werkzeug always passes errors through1242 assert rv['passthrough_errors']124312441245def test_max_content_length():1246 app = flask.Flask(__name__)1247 app.config['MAX_CONTENT_LENGTH'] = 641248
390 unmodified lines