Skip to content
Myr

Added a PROPAGATE_EXCEPTIONS flag

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

authored by Armin Ronacher · committed by Armin Ronacher · parent ed517c7 · Browse files · 4 files+54 added−2 removed
This commit

State

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

Diff stats

4 files+54 added−2 removed

  • tests:+28 added−1 removed
  • other:+26 added−1 removed

4 files+54 added−2 removed

modified:docs/config.rst+8 added
52 unmodified lines
5354=============================== =========================================55``DEBUG`` enable/disable debug mode56``TESTING`` enable/disable testing mode57``PROPAGATE_EXCEPTIONS`` explicitly enable or disable the58 propagation of exceptions. If not set or59 explicitly set to `None` this is60 implicitly true if either `TESTING` or61 `DEBUG` is true.62``SECRET_KEY`` the secret key63``SESSION_COOKIE_NAME`` the name of the session cookie64``PERMANENT_SESSION_LIFETIME`` the lifetime of a permanent session as65 :class:`datetime.timedelta` object.
34 unmodified lines
100101.. versionadded:: 0.6102 ``MAX_CONTENT_LENGTH``103104.. versionadded:: 0.7105 ``PROPAGATE_EXCEPTIONS``106107Configuring from Files108----------------------109110Configuration becomes more useful if you can configure from a file, and
126 unmodified lines
modified:flask/app.py+14 added-1 removed
187 unmodified lines
188 #: Default configuration parameters.189 default_config = ImmutableDict({190 'DEBUG': False,191 'TESTING': False,192 'PROPAGATE_EXCEPTIONS': None,193 'SECRET_KEY': None,194 'SESSION_COOKIE_NAME': 'session',195 'PERMANENT_SESSION_LIFETIME': timedelta(days=31),196 'USE_X_SENDFILE': False,
107 unmodified lines
304 self.jinja_env = self.create_jinja_environment()305 self.init_jinja_globals()306307 @property308 def propagate_exceptions(self):309 """Returns the value of the `PROPAGATE_EXCEPTIONS` configuration310 value in case it's set, otherwise a sensible default is returned.311312 .. versionadded:: 0.7313 """314 rv = self.config['PROPAGATE_EXCEPTIONS']315 if rv is not None:316 return rv317 return self.testing or self.debug318319 @property320 def logger(self):321 """A :class:`logging.Logger` object for this application. The322 default configuration is to log to stderr if the application is323 in debug mode. This logger can be used to (surprise) log messages.
370 unmodified lines
694 .. versionadded: 0.3695 """696 got_request_exception.send(self, exception=e)697 handler = self.error_handlers.get(500)685 if self.debug:698 if self.propagate_exceptions:699 raise700 self.logger.exception('Exception on %s [%s]' % (701 request.path,702 request.method
233 unmodified lines
modified:tests/flask_tests.py+28 added-1 removed
13 unmodified lines
14import re15import sys16import flask17import unittest18from threading import Thread19from logging import StreamHandler20from contextlib import contextmanager21from datetime import datetime22from werkzeug import parse_date, parse_options_header
524 unmodified lines
547 raise ValueError(548 "No ValueError exception should have been raised \"%s\"" % e549 )550550551 def test_test_app_proper_environ(self):552 app = flask.Flask(__name__)553 app.config.update(554 SERVER_NAME='localhost.localdomain:5000'
63 unmodified lines
618 raise ValueError(619 "No ValueError exception should have been raised \"%s\"" % e620 )621622 def test_exception_propagation(self):623 def apprunner(configkey):624 app = flask.Flask(__name__)625 @app.route('/')626 def index():627 1/0628 c = app.test_client()629 if config_key is not None:630 app.config[config_key] = True631 try:632 resp = c.get('/')633 except Exception:634 pass635 else:636 self.fail('expected exception')637 else:638 assert c.get('/').status_code == 500639640 # we have to run this test in an isolated thread because if the641 # debug flag is set to true and an exception happens the context is642 # not torn down. This causes other tests that run after this fail643 # when they expect no exception on the stack.644 for config_key in 'TESTING', 'PROPAGATE_EXCEPTIONS', 'DEBUG', None:645 t = Thread(target=apprunner, args=(config_key,))646 t.start()647 t.join()648649650class JSONTestCase(unittest.TestCase):651652 def test_jsonify(self):653 d = dict(a=23, b=42, c=[1, 2, 3])
744 unmodified lines
modified:CHANGES+4 added
21 unmodified lines
22 was not reliable and caused issues on Google's App Engine. Until23 1.0 the old behaviour will continue to work but issue dependency24 warnings.25- fixed a problem for Flask to run on jython.26- added a `PROPAGATE_EXCEPTIONS` configuration variable that can be27 used to flip the setting of exception propagation which previously28 was linked to `DEBUG` alone and is now linked to either `DEBUG` or29 `TESTING`.3031Version 0.6.132-------------33
156 unmodified lines