Skip to content

fix(utils): Check that __module__ is str #3942

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

Merged
merged 1 commit into from
Jan 20, 2025
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: 1 addition & 1 deletion sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ def qualname_from_function(func):

# Python 3: methods, functions, classes
if func_qualname is not None:
if hasattr(func, "__module__"):
if hasattr(func, "__module__") and isinstance(func.__module__, str):
func_qualname = func.__module__ + "." + func_qualname
func_qualname = prefix + func_qualname + suffix

Expand Down
20 changes: 20 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,3 +951,23 @@ def test_format_timestamp_naive():
# Ensure that some timestamp is returned, without error. We currently treat these as local time, but this is an
# implementation detail which we should not assert here.
assert re.fullmatch(timestamp_regex, format_timestamp(datetime_object))


def test_qualname_from_function_inner_function():
def test_function(): ...

assert (
sentry_sdk.utils.qualname_from_function(test_function)
== "tests.test_utils.test_qualname_from_function_inner_function.<locals>.test_function"
)


def test_qualname_from_function_none_name():
def test_function(): ...

test_function.__module__ = None

assert (
sentry_sdk.utils.qualname_from_function(test_function)
== "test_qualname_from_function_none_name.<locals>.test_function"
)
Loading