Skip to content

fix(api): push_scope deprecation warning #3355

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
Jul 26, 2024
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
14 changes: 12 additions & 2 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,19 @@ def push_scope( # noqa: F811
:returns: If no `callback` is provided, a context manager that should
be used to pop the scope again.
"""
warnings.warn(
"sentry_sdk.push_scope is deprecated and will be removed in the next major version. "
"Please consult our migration guide to learn how to migrate to the new API: "
"https://docs.sentry.io/platforms/python/migration/1.x-to-2.x#scope-pushing",
DeprecationWarning,
stacklevel=2,
)

if callback is not None:
with push_scope() as scope:
callback(scope)
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
with push_scope() as scope:
callback(scope)
return None

return _ScopeManager()
Expand Down
7 changes: 7 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
start_transaction,
set_tags,
configure_scope,
push_scope,
)

from sentry_sdk.client import Client, NonRecordingClient
Expand Down Expand Up @@ -186,3 +187,9 @@ def test_configure_scope_deprecation():
with pytest.warns(DeprecationWarning):
with configure_scope():
...


def test_push_scope_deprecation():
with pytest.warns(DeprecationWarning):
with push_scope():
...
6 changes: 4 additions & 2 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def before_breadcrumb(crumb, hint):
add_breadcrumb(crumb=dict(foo=42))


def test_push_scope(sentry_init, capture_events):
def test_push_scope(sentry_init, capture_events, suppress_deprecation_warnings):
sentry_init()
events = capture_events()

Expand All @@ -312,7 +312,9 @@ def test_push_scope(sentry_init, capture_events):
assert "exception" in event


def test_push_scope_null_client(sentry_init, capture_events):
def test_push_scope_null_client(
sentry_init, capture_events, suppress_deprecation_warnings
):
"""
This test can be removed when we remove push_scope and the Hub from the SDK.
"""
Expand Down
Loading