Skip to content
Myr

Merge pull request #2739 from pallets/2735-abort-debug

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

Only trap key errors by default in debug, not all BadRequest errors

authored by David Lord · committed by GitHub · parents 27d56c1, b573a86 · Browse files · 2 files+27 added−8 removed
This commit

State

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

Diff stats

2 files+27 added−8 removed

  • tests:+19 added−6 removed
  • other:+8 added−2 removed

2 files+27 added−8 removed

modified:flask/app.py+8 added-2 removed
1661 unmodified lines
1662 return True16631664 trap_bad_request = self.config['TRAP_BAD_REQUEST_ERRORS']16651666 # if unset, trap based on debug mode1667 if (trap_bad_request is None and self.debug) or trap_bad_request:1666 # if unset, trap key errors in debug mode1667 if (1668 trap_bad_request is None and self.debug1669 and isinstance(e, BadRequestKeyError)1670 ):1671 return True16721673 if trap_bad_request:1674 return isinstance(e, BadRequest)16751676 return False1677
636 unmodified lines
modified:tests/test_basic.py+19 added-6 removed
1025 unmodified lines
1026 assert rv.data == b'E2'102710281029def test_trapping_of_bad_request_key_errors(app, client):1030 @app.route('/fail')1030 @app.route('/key')1031 def fail():1032 flask.request.form['missing_key']10331034 @app.route('/abort')1035 def allow_abort():1036 flask.abort(400)10371034 rv = client.get('/fail')1038 rv = client.get('/key')1039 assert rv.status_code == 4001040 assert b'missing_key' not in rv.data1041 rv = client.get('/abort')1042 assert rv.status_code == 40010431038 app.config['TRAP_BAD_REQUEST_ERRORS'] = True10391044 app.debug = True1045 with pytest.raises(KeyError) as e:1041 client.get("/fail")10421046 client.get("/key")1047 assert e.errisinstance(BadRequest)1048 assert 'missing_key' in e.value.description1049 rv = client.get('/abort')1050 assert rv.status_code == 40010511052 app.debug = False1053 app.config['TRAP_BAD_REQUEST_ERRORS'] = True1054 with pytest.raises(KeyError):1055 client.get('/key')1056 with pytest.raises(BadRequest):1057 client.get('/abort')105810591060def test_trapping_of_all_http_exceptions(app, client):1061 app.config['TRAP_HTTP_EXCEPTIONS'] = True10621063 @app.route('/fail')
899 unmodified lines