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
1 change: 1 addition & 0 deletions sentry_sdk/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
PY2 = sys.version_info[0] == 2
PY33 = sys.version_info[0] == 3 and sys.version_info[1] >= 3
PY37 = sys.version_info[0] == 3 and sys.version_info[1] >= 7
PY310 = sys.version_info[0] == 3 and sys.version_info[1] >= 10

if PY2:
import urlparse
Expand Down
10 changes: 7 additions & 3 deletions sentry_sdk/integrations/django/signals_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ def _get_receiver_name(receiver):
name = ""

if hasattr(receiver, "__qualname__"):
name += receiver.__qualname__
name = receiver.__qualname__
elif hasattr(receiver, "__name__"): # Python 2.7 has no __qualname__
name += receiver.__name__
name = receiver.__name__
elif hasattr(
receiver, "func"
): # certain functions (like partials) dont have a name
name = "partial(<function " + receiver.func.__name__ + ">)" # type: ignore

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can the func itself be a partial?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

F*ck... Probably... I will check on Monday

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will check now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, func appears to always be the function:

Python 3.10.8 (main, Oct 13 2022, 09:48:40) [Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def f(a, b, c, x):
...     return 1000*a + 100*b + 10*c + x
... 
>>> f
<function f at 0x102752050>
>>> from functools import partial
>>> g = partial(f, 3)
>>> h = partial(g, 1)
>>> g
functools.partial(<function f at 0x102752050>, 3)
>>> h
functools.partial(<function f at 0x102752050>, 3, 1)
>>> h(3, 4)
3134
>>> h.func
<function f at 0x102752050>
>>> g.func
<function f at 0x102752050>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cool, thx for checking


if (
name == ""
): # certain functions (like partials) dont have a name so return the string representation
): # In case nothing was found, return the string representation (this is the slowest case)
return str(receiver)

if hasattr(receiver, "__module__"): # prepend with module, if there is one
Expand Down
3 changes: 2 additions & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Werkzeug<2.1.0
jsonschema==3.2.0
pyrsistent==0.16.0 # TODO(py3): 0.17.0 requires python3, see https://github.com/tobgu/pyrsistent/issues/205
executing
asttokens
asttokens
ipdb
7 changes: 5 additions & 2 deletions tests/integrations/django/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
except ImportError:
from django.core.urlresolvers import reverse

from sentry_sdk._compat import PY2
from sentry_sdk._compat import PY2, PY310
from sentry_sdk import capture_message, capture_exception, configure_scope
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.django.signals_handlers import _get_receiver_name
Expand Down Expand Up @@ -834,4 +834,7 @@ def dummy(a, b):

a_partial = partial(dummy)
name = _get_receiver_name(a_partial)
assert name == str(a_partial)
if PY310:
assert name == "functools.partial(<function " + a_partial.func.__name__ + ">)"
else:
assert name == "partial(<function " + a_partial.func.__name__ + ">)"