Skip to content

Commit a046901

Browse files
ref: should_send_default_pii shortcut (#2844)
Currently, with the new scope API, calls to hub._should_send_default_pii need to be replaced with calls to sentry_sdk.get_client().should_send_default_pii. This PR introduces scope.should_send_default_pii as a drop-in replacement for hub._should_send_default_pii, so we don't need to type out sentry_sdk.get_client().should_send_default_pii everywhere we need to check should_send_default_pii.
1 parent 553045b commit a046901

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

sentry_sdk/hub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def overload(x):
6060

6161
def _should_send_default_pii():
6262
# type: () -> bool
63-
# TODO: Migrate existing code to client.should_send_default_pii() and remove this function.
63+
# TODO: Migrate existing code to `scope.should_send_default_pii()` and remove this function.
6464
# New code should not use this function!
6565
client = Hub.current.client
6666
if not client:

sentry_sdk/scope.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,5 +1658,11 @@ def use_isolation_scope(isolation_scope):
16581658
_isolation_scope.reset(isolation_token)
16591659

16601660

1661+
def should_send_default_pii():
1662+
# type: () -> bool
1663+
"""Shortcut for `Scope.get_client().should_send_default_pii()`."""
1664+
return Scope.get_client().should_send_default_pii()
1665+
1666+
16611667
# Circular imports
16621668
from sentry_sdk.client import NonRecordingClient

tests/test_scope.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
new_scope,
1111
)
1212
from sentry_sdk.client import Client, NonRecordingClient
13-
from sentry_sdk.scope import Scope, ScopeType, use_isolation_scope, use_scope
13+
from sentry_sdk.scope import (
14+
Scope,
15+
ScopeType,
16+
use_isolation_scope,
17+
use_scope,
18+
should_send_default_pii,
19+
)
1420

1521

1622
def test_copying():
@@ -778,3 +784,15 @@ def test_nested_scopes_with_tags(sentry_init, capture_envelopes):
778784
assert transaction["tags"] == {"isolation_scope1": 1, "current_scope2": 1, "trx": 1}
779785
assert transaction["spans"][0]["tags"] == {"a": 1}
780786
assert transaction["spans"][1]["tags"] == {"b": 1}
787+
788+
789+
def test_should_send_default_pii_true(sentry_init):
790+
sentry_init(send_default_pii=True)
791+
792+
assert should_send_default_pii() is True
793+
794+
795+
def test_should_send_default_pii_false(sentry_init):
796+
sentry_init(send_default_pii=False)
797+
798+
assert should_send_default_pii() is False

0 commit comments

Comments
 (0)