Skip to content

Commit

Permalink
Werkzeug should not block propagated exceptions from Flask
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Jan 2, 2016
1 parent f17e606 commit 952a6c8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ def run(self, host=None, port=None, debug=None, **options):
self.debug = bool(debug)
options.setdefault('use_reloader', self.debug)
options.setdefault('use_debugger', self.debug)
options.setdefault('passthrough_errors', True)
try:
run_simple(host, port, self, **options)
finally:
Expand Down
3 changes: 2 additions & 1 deletion flask/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ def run_command(info, host, port, reload, debugger, eager_loading,
print(' * Forcing debug %s' % (info.debug and 'on' or 'off'))

run_simple(host, port, app, use_reloader=reload,
use_debugger=debugger, threaded=with_threads)
use_debugger=debugger, threaded=with_threads,
passthrough_errors=True)


@click.command('shell', short_help='Runs a shell in the app context.')
Expand Down
20 changes: 20 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,26 @@ def index():
t.join()


@pytest.mark.parametrize('debug', [True, False])
@pytest.mark.parametrize('use_debugger', [True, False])
@pytest.mark.parametrize('use_reloader', [True, False])
@pytest.mark.parametrize('propagate_exceptions', [None, True, False])
def test_werkzeug_passthrough_errors(monkeypatch, debug, use_debugger,
use_reloader, propagate_exceptions):
rv = {}

# Mocks werkzeug.serving.run_simple method
def run_simple_mock(*args, **kwargs):
rv['passthrough_errors'] = kwargs.get('passthrough_errors')

app = flask.Flask(__name__)
monkeypatch.setattr(werkzeug.serving, 'run_simple', run_simple_mock)
app.config['PROPAGATE_EXCEPTIONS'] = propagate_exceptions
app.run(debug=debug, use_debugger=use_debugger, use_reloader=use_reloader)
# make sure werkzeug always passes errors through
assert rv['passthrough_errors']


def test_max_content_length():
app = flask.Flask(__name__)
app.config['MAX_CONTENT_LENGTH'] = 64
Expand Down

0 comments on commit 952a6c8

Please sign in to comment.