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(tests): Fix exception on copying frame.f_locals (Python 3.13) #3271

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
3 changes: 1 addition & 2 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import threading
import time
from collections import namedtuple
from copy import copy
from datetime import datetime
from decimal import Decimal
from functools import partial, partialmethod, wraps
Expand Down Expand Up @@ -618,7 +617,7 @@ def serialize_frame(
)

if include_local_variables:
rv["vars"] = copy(frame.f_locals)
rv["vars"] = frame.f_locals.copy()

return rv

Expand Down
7 changes: 7 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
from sentry_sdk._types import Event


maximum_python_312 = pytest.mark.skipif(
sys.version_info > (3, 12),
reason="Since Python 3.13, `FrameLocalsProxy` skips items of `locals()` that have non-`str` keys; this is a CPython implementation detail: https://github.com/python/cpython/blame/7b413952e817ae87bfda2ac85dd84d30a6ce743b/Objects/frameobject.c#L148",
)


class EnvelopeCapturedError(Exception):
pass

Expand Down Expand Up @@ -879,6 +885,7 @@ class FooError(Exception):
assert exception["mechanism"]["meta"]["errno"]["number"] == 69


@maximum_python_312
def test_non_string_variables(sentry_init, capture_events):
"""There is some extremely terrible code in the wild that
inserts non-strings as variable names into `locals()`."""
Expand Down
Loading