Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Unreleased
float values. (:issue:`1511`)
- Update :class:`~middleware.lint.LintMiddleware` to work on Python 3.
(:issue:`1510`)
- The debugger detects cycles in chained exceptions and does not time
out in that case. (:issue:`1536`)


Version 0.15.2
Expand Down
4 changes: 3 additions & 1 deletion src/werkzeug/debug/tbtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,14 @@ def __init__(self, exc_type, exc_value, tb):
self.exception_type = exception_type

self.groups = []
memo = set()
while True:
self.groups.append(Group(exc_type, exc_value, tb))
memo.add(exc_value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this assumes hashability of exceptions (which isn't always true), I wrote a fix for this: #1542

if PY2:
break
exc_value = exc_value.__cause__ or exc_value.__context__
if exc_value is None:
if exc_value is None or exc_value in memo:
break
exc_type = type(exc_value)
tb = exc_value.__traceback__
Expand Down
17 changes: 17 additions & 0 deletions tests/test_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,20 @@ def app(environ, start_response):
assert "The debugger caught an exception in your WSGI application" in r.text
else:
assert r.text == "hello"


@pytest.mark.skipif(PY2, reason="Python 2 doesn't have chained exceptions.")
@pytest.mark.timeout(2)
def test_chained_exception_cycle():
try:
try:
raise ValueError()
except ValueError:
raise TypeError()
except TypeError as e:
# create a cycle and make it available outside the except block
e.__context__.__context__ = error = e

# if cycles aren't broken, this will time out
tb = Traceback(TypeError, error, error.__traceback__)
assert len(tb.groups) == 2
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ skip_missing_interpreters = true
deps =
coverage
pytest
pytest-timeout
pytest-xprocess
requests
requests_unixsocket
Expand Down