Skip to content

Commit

Permalink
Fix unhashable exception types
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed May 12, 2019
1 parent bdc17e4 commit 0e669f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/werkzeug/debug/tbtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ def __init__(self, exc_type, exc_value, tb):
memo = set()
while True:
self.groups.append(Group(exc_type, exc_value, tb))
memo.add(exc_value)
memo.add(id(exc_value))
if PY2:
break
exc_value = exc_value.__cause__ or exc_value.__context__
if exc_value is None or exc_value in memo:
if exc_value is None or id(exc_value) in memo:
break
exc_type = type(exc_value)
tb = exc_value.__traceback__
Expand Down
11 changes: 11 additions & 0 deletions tests/test_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,14 @@ def test_chained_exception_cycle():
# if cycles aren't broken, this will time out
tb = Traceback(TypeError, error, error.__traceback__)
assert len(tb.groups) == 2


def test_non_hashable_exception():
class MutableException(ValueError):
__hash__ = None

try:
raise MutableException()
except MutableException:
# previously crashed: `TypeError: unhashable type 'MutableException'`
Traceback(*sys.exc_info())

0 comments on commit 0e669f6

Please sign in to comment.