Changed teardown error handling to be more reliable.
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 90e3906 · Browse files · 3 files·+30 added−6 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+30 added−6 removed
- other:+30 added−6 removed
Provenance
- Commit
f191809- Tree
9d2cdd2- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
90e3906
3 files changed+30 added−6 removed
modified:flask/app.py+19 added-1 removed
1508 unmodified lines1509 rv = self.response_class()1510 rv.allow.update(methods)1511 return rv1512 1513+ def should_ignore_error(self, error):1514+ """This is called to figure out if an error should be ignored1515+ or not as far as the teardown system is concerned. If this1516+ function returns `True` then the teardown handlers will not be1517+ passed the error.1518+1519+ .. versionadded:: 0.101520+ """1521+ return False1522+1523 def make_response(self, rv):1524 """Converts the return value from a view function to a real1525 response object that is an instance of :attr:`response_class`.1526 272 unmodified lines1799 :param start_response: a callable accepting a status code,1800 a list of headers and an optional1801 exception context to start the response1802 """1793- with self.request_context(environ):1803+ ctx = self.request_context(environ)1804+ ctx.push()1805+ error = None1806+ try:1807 try:1808 response = self.full_dispatch_request()1809 except Exception as e:1810+ error = e1811 response = self.make_response(self.handle_exception(e))1812 return response(environ, start_response)1813+ finally:1814+ if self.should_ignore_error(error):1815+ error = None1816+ ctx.auto_pop(error)1817 1818 @property1819 def modules(self):1820 from warnings import warn13 unmodified linesmodified:flask/ctx.py+8 added-5 removed
350 unmodified lines351 # Get rid of the app as well if necessary.352 if app_ctx is not None:353 app_ctx.pop(exc)354 355+ def auto_pop(self, exc):356+ if self.request.environ.get('flask._preserve_context') or \357+ (exc is not None and self.app.preserve_context_on_exception):358+ self.preserved = True359+ else:360+ self.pop(exc)361+362 def __enter__(self):363 self.push()364 return self365 2 unmodified lines368 # exception happened. This will allow the debugger to still369 # access the request object in the interactive shell. Furthermore370 # the context can be force kept alive for the test client.371 # See flask.testing for how this works.365- if self.request.environ.get('flask._preserve_context') or \366- (tb is not None and self.app.preserve_context_on_exception):367- self.preserved = True368- else:369- self.pop(exc_value)372+ self.auto_pop(exc_value)373 374 def __repr__(self):375 return '<%s \'%s\' [%s] of %s>' % (376 self.__class__.__name__,4 unmodified linesmodified:CHANGES+3 added
57 unmodified lines58 you can reintroduce them again yourself trivially. Using them however is59 strongly discouraged as the interface was flawed.60 - Python requirements changed: requiring Python 2.6 or 2.7 now to prepare61 for Python 3.3 port.62+- Changed how the teardown system is informed about exceptions. This is now63+ more reliable in case something handles an exception halfway through64+ the error handling process.65 66 Version 0.967 -----------68 365 unmodified lines