Skip to content

Commit a85f0fb

Browse files
fix(utils): Check that __module__ is str (#3942)
Fixes #3939
1 parent 3f57299 commit a85f0fb

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

sentry_sdk/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,7 @@ def qualname_from_function(func):
15011501

15021502
# Python 3: methods, functions, classes
15031503
if func_qualname is not None:
1504-
if hasattr(func, "__module__"):
1504+
if hasattr(func, "__module__") and isinstance(func.__module__, str):
15051505
func_qualname = func.__module__ + "." + func_qualname
15061506
func_qualname = prefix + func_qualname + suffix
15071507

tests/test_utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,3 +951,23 @@ def test_format_timestamp_naive():
951951
# Ensure that some timestamp is returned, without error. We currently treat these as local time, but this is an
952952
# implementation detail which we should not assert here.
953953
assert re.fullmatch(timestamp_regex, format_timestamp(datetime_object))
954+
955+
956+
def test_qualname_from_function_inner_function():
957+
def test_function(): ...
958+
959+
assert (
960+
sentry_sdk.utils.qualname_from_function(test_function)
961+
== "tests.test_utils.test_qualname_from_function_inner_function.<locals>.test_function"
962+
)
963+
964+
965+
def test_qualname_from_function_none_name():
966+
def test_function(): ...
967+
968+
test_function.__module__ = None
969+
970+
assert (
971+
sentry_sdk.utils.qualname_from_function(test_function)
972+
== "test_qualname_from_function_none_name.<locals>.test_function"
973+
)

0 commit comments

Comments
 (0)