diff options
author | Lars Mikkelsen <lars@ionic.io> | 2018-09-25 07:06:07 -0400 |
---|---|---|
committer | Markus Unterwaditzer <markus@unterwaditzer.net> | 2018-09-25 13:06:07 +0200 |
commit | 719be9afae528962e683d086f9c2ceeda07f881b (patch) | |
tree | 92765619c6a1f9dd24a7bde03dbc0b441cce7097 | |
parent | 6307373dee9596995c5d35b349e9c8ba688b2a5d (diff) | |
download | raven-719be9afae528962e683d086f9c2ceeda07f881b.tar.gz |
Use correct kwarg in handle_exception() for Flask (#1300)
* Use correct kwarg in handle_exception() for Flask
The handle_exception() method is registered as a receiver of the
got_request_exception signal. According to both the [documentation][1]
and [source code][2] of Flask the got_request_exception signal passes
the exception as `exception` rather than a `exc_info`.
This is likely to have gone unnoticed since captureException() calls
sys.exc_info() in the absence of an exception.
On Python 3 we can use `__traceback__` to explicitly construct the
`exc_info`.
[1]: http://flask.pocoo.org/docs/1.0/api/#flask.got_request_exception
[2]: https://github.com/pallets/flask/blob/1.0.2/flask/app.py#L1732
* doc: Add changelog
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | raven/contrib/flask.py | 11 |
2 files changed, 11 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 25e410b..e7c8a73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ------ * [Core] Fixed stackframes in some situations being in inverse order. +* [Flask] Fix wrong exception handling logic (accidentally relied on Flask internals). 6.9.0 (2018-05-30) ------------------ diff --git a/raven/contrib/flask.py b/raven/contrib/flask.py index 40c7fb3..0a3f750 100644 --- a/raven/contrib/flask.py +++ b/raven/contrib/flask.py @@ -136,7 +136,16 @@ class Sentry(object): if not self.client: return - self.captureException(exc_info=kwargs.get('exc_info')) + # got_request_exception signal passes the exception as 'exception' + exception = kwargs.get('exception') + if exception is not None and hasattr(exception, '__traceback__'): + # On Python 3 we can contruct the exc_info via __traceback__ + exc_info = (type(exception), exception, exception.__traceback__) + else: + # The user may call the method with 'exc_info' manually + exc_info = kwargs.get('exc_info') + + self.captureException(exc_info=exc_info) def get_user_info(self, request): """ |