Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: max recursion depth exceeded #335

Merged
merged 1 commit into from
Jun 5, 2024
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
6 changes: 5 additions & 1 deletion _appmap/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,11 @@ class FuncReturnEvent(ReturnEvent):

def __init__(self, parent_id, elapsed, return_value):
super().__init__(parent_id, elapsed)
self.return_value = describe_value(None, return_value)
# Import here to prevent circular dependency
# pylint: disable=import-outside-toplevel
from _appmap.instrument import recording_disabled # noqa: F401
with recording_disabled():
self.return_value = describe_value(None, return_value)


class HttpResponseEvent(ReturnEvent):
Expand Down
3 changes: 2 additions & 1 deletion _appmap/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
@contextmanager
def recording_disabled():
tls = appmap_tls()
original_value = tls.get("instrumentation_disabled")
tls["instrumentation_disabled"] = True
try:
yield
finally:
tls["instrumentation_disabled"] = False
tls["instrumentation_disabled"] = original_value


def is_instrumentation_disabled():
Expand Down
3 changes: 3 additions & 0 deletions _appmap/test/data/example_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def with_docstring(self):
def with_comment(self):
return True

def return_self(self):
return self


def modfunc():
return "Hello world!"
12 changes: 12 additions & 0 deletions _appmap/test/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,15 @@ def test_when_display_disabled(self, mocker):
# MagicMock. (If it's broken, we may not get here at all,
# because the assertion above may fail.)
param.__repr__.assert_called_once_with()

def test_describe_return_value_recursion_protection(self):
r = appmap.Recording()
with r:
# pylint: disable=import-outside-toplevel
from example_class import ExampleClass

ExampleClass().return_self()
# There should be no event for method another_method which is called by __repr__.
assert [e.method_id for e in r.events if e.event == "call" and hasattr(e, "method_id")] == [
"return_self"
]
Loading