fix(api): Fix tracing TypeError for static and class methods#2559
Conversation
| def test_staticmethod_patching(sentry_init): | ||
| test_staticmethod_name = "test_decorator_py3.TestClass.static" | ||
| assert ( | ||
| ".".join([TestClass.static.__module__, TestClass.static.__qualname__]) | ||
| == test_staticmethod_name | ||
| ), "The test static method was moved or renamed. Please update the name accordingly" | ||
|
|
||
| sentry_init(functions_to_trace=[{"qualified_name": test_staticmethod_name}]) | ||
|
|
||
| for instance_or_class in (TestClass, TestClass()): | ||
| with patch_start_child() as fake_start_child: | ||
| assert instance_or_class.static(1) == 1 | ||
| fake_start_child.assert_called_once() | ||
|
|
||
|
|
||
| def test_classmethod_patching(sentry_init): | ||
| test_classmethod_name = "test_decorator_py3.TestClass.class_" | ||
| assert ( | ||
| ".".join([TestClass.class_.__module__, TestClass.class_.__qualname__]) | ||
| == test_classmethod_name | ||
| ), "The test class method was moved or renamed. Please update the name accordingly" | ||
|
|
||
| sentry_init(functions_to_trace=[{"qualified_name": test_classmethod_name}]) | ||
|
|
||
| for instance_or_class in (TestClass, TestClass()): | ||
| with patch_start_child() as fake_start_child: | ||
| assert instance_or_class.class_(1) == (TestClass, 1) | ||
| fake_start_child.assert_called_once() |
There was a problem hiding this comment.
We should probably move these to test_basics since they are not specific to the test decorator and should also run on Python 2 (put them here originally when I thought I would fix the bug differently)
There was a problem hiding this comment.
Fine with me either way
| @@ -0,0 +1,48 @@ | |||
| from unittest import mock | |||
There was a problem hiding this comment.
This file moved from tests/tracing/test_decorator_py3.py
|
I decided to move the tests I created to |
| transaction.set_http_status(response.status) | ||
| return response | ||
|
|
||
| Application._handle = sentry_app_handle # type: ignore[method-assign] |
There was a problem hiding this comment.
mypy was complaining about the type: ignore comments in this file, so I had to make changes here, even though the changes are unrelated to the rest of the PR
Fixes TypeError that occurred when static or class methods, which were passed in the
functions_to_traceargument when initializing the SDK, were called on an instance.We also need to update docs to specify order when using
sentry_sdk.tracedecorator (as in the workaround I suggested on the issue)Fixes GH-2525