Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Use correct kwarg in handle_exception() for Flask (#1300)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ltm authored and untitaker committed Sep 25, 2018
1 parent 6307373 commit 719be9a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------
Expand Down
11 changes: 10 additions & 1 deletion raven/contrib/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,16 @@ def handle_exception(self, *args, **kwargs):
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):
"""
Expand Down

0 comments on commit 719be9a

Please sign in to comment.