From 2b510f51866f3764a2b092bc8f03d2cb9b3b2737 Mon Sep 17 00:00:00 2001 From: Pablo Deputter Date: Thu, 24 Sep 2026 11:05:57 +0200 Subject: [PATCH 1/3] ref(pyramid): Drop `send_default_pii` support --- sentry_sdk/integrations/pyramid.py | 17 ++-------- tests/integrations/pyramid/test_pyramid.py | 38 ++++++++++++++++++---- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/sentry_sdk/integrations/pyramid.py b/sentry_sdk/integrations/pyramid.py index 7707917c68..e2f29b8054 100644 --- a/sentry_sdk/integrations/pyramid.py +++ b/sentry_sdk/integrations/pyramid.py @@ -8,13 +8,11 @@ from sentry_sdk.integrations import DidNotEnable, Integration, _check_minimum_version from sentry_sdk.integrations._wsgi_common import RequestExtractor from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware -from sentry_sdk.scope import should_send_default_pii from sentry_sdk.traces import SOURCE_FOR_STYLE as SEGMENT_SOURCE_FOR_STYLE from sentry_sdk.utils import ( capture_internal_exceptions, ensure_integration_enabled, event_from_exception, - has_data_collection_enabled, package_version, reraise, ) @@ -92,12 +90,7 @@ def sentry_patched_call_view( scope = sentry_sdk.get_isolation_scope() - if has_data_collection_enabled(client.options): - if client.options["data_collection"]["user_info"]: - user_id = request.authenticated_userid - if user_id: - scope.set_user({"id": user_id}) - elif should_send_default_pii(): + if client.options["data_collection"]["user_info"]: user_id = request.authenticated_userid if user_id: scope.set_user({"id": user_id}) @@ -233,12 +226,8 @@ def pyramid_event_processor(event: "Event", hint: "Dict[str, Any]") -> "Event": PyramidRequestExtractor(request).extract_into_event(event) client_options = sentry_sdk.get_client().options - if has_data_collection_enabled(client_options): - if client_options["data_collection"]["user_info"]: - with capture_internal_exceptions(): - user_info = event.setdefault("user", {}) - user_info.setdefault("id", request.authenticated_userid) - elif should_send_default_pii(): + + if client_options["data_collection"]["user_info"]: with capture_internal_exceptions(): user_info = event.setdefault("user", {}) user_info.setdefault("id", request.authenticated_userid) diff --git a/tests/integrations/pyramid/test_pyramid.py b/tests/integrations/pyramid/test_pyramid.py index 798accbf73..3de340c6bd 100644 --- a/tests/integrations/pyramid/test_pyramid.py +++ b/tests/integrations/pyramid/test_pyramid.py @@ -15,7 +15,6 @@ from sentry_sdk.serializer import MAX_DATABAG_BREADTH from sentry_sdk.traces import SpanStatus from tests.conftest import unpack_werkzeug_response -from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES def hi(request): @@ -93,7 +92,7 @@ def errors(request): def test_has_context(route, get_client, sentry_init, capture_events): - sentry_init(integrations=[PyramidIntegration()]) + sentry_init(integrations=[PyramidIntegration()], data_collection={}) events = capture_events() @route("/context_message/{msg}") @@ -110,7 +109,6 @@ def hi2(request): "env": {"SERVER_NAME": "localhost", "SERVER_PORT": "80"}, "headers": {"Host": "localhost"}, "method": "GET", - "query_string": "", "url": "http://localhost/context_message/yoo", } assert event["transaction"] == "hi2" @@ -403,11 +401,11 @@ def test_error_in_authenticated_userid( from sentry_sdk.integrations.logging import LoggingIntegration sentry_init( - send_default_pii=True, integrations=[ PyramidIntegration(), LoggingIntegration(event_level=logging.ERROR), ], + data_collection={}, ) logger = logging.getLogger("test_pyramid") @@ -531,7 +529,21 @@ def test_span_origin( assert segment["attributes"]["sentry.origin"] == "auto.http.pyramid" -@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_user", + [ + pytest.param( + {"data_collection": {"user_info": True}}, + True, + id="data_collection_user_info_true", + ), + pytest.param( + {"data_collection": {"user_info": False}}, + False, + id="data_collection_user_info_false", + ), + ], +) def test_span_sets_user_id_on_segment( sentry_init, pyramid_config, @@ -570,7 +582,21 @@ def authenticated_userid(self, request): assert "user.id" not in segment["attributes"] -@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES) +@pytest.mark.parametrize( + "init_kwargs, expect_user", + [ + pytest.param( + {"data_collection": {"user_info": True}}, + True, + id="data_collection_user_info_true", + ), + pytest.param( + {"data_collection": {"user_info": False}}, + False, + id="data_collection_user_info_false", + ), + ], +) def test_user_id_error_event_data_collection( sentry_init, pyramid_config, From 90919fc853519064725f83769f880e42a6506341 Mon Sep 17 00:00:00 2001 From: Pablo Deputter Date: Thu, 24 Sep 2026 11:21:47 +0200 Subject: [PATCH 2/3] ref(pyramid): Add missing `data_collection={}` to `sentry_init` --- tests/integrations/pyramid/test_pyramid.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/integrations/pyramid/test_pyramid.py b/tests/integrations/pyramid/test_pyramid.py index 3de340c6bd..6b068acf32 100644 --- a/tests/integrations/pyramid/test_pyramid.py +++ b/tests/integrations/pyramid/test_pyramid.py @@ -180,6 +180,7 @@ def test_large_json_request( integrations=[PyramidIntegration()], max_request_body_size="always", max_value_length=max_value_length, + data_collection={}, ) data = {"foo": {"bar": "a" * (1034)}} @@ -213,7 +214,7 @@ def index(request): @pytest.mark.parametrize("data", [{}, []], ids=["empty-dict", "empty-list"]) def test_flask_empty_json_request(sentry_init, capture_events, route, get_client, data): - sentry_init(integrations=[PyramidIntegration()]) + sentry_init(integrations=[PyramidIntegration()], data_collection={}) @route("/") def index(request): @@ -236,7 +237,11 @@ def index(request): def test_json_not_truncated_if_max_request_body_size_is_always( sentry_init, capture_events, route, get_client ): - sentry_init(integrations=[PyramidIntegration()], max_request_body_size="always") + sentry_init( + integrations=[PyramidIntegration()], + max_request_body_size="always", + data_collection={}, + ) data = { "key{}".format(i): "value{}".format(i) for i in range(MAX_DATABAG_BREADTH + 10) @@ -266,6 +271,7 @@ def test_files_and_form( integrations=[PyramidIntegration()], max_request_body_size="always", max_value_length=max_value_length, + data_collection={}, ) data = { From dd9bfe6d85bd0858a409277f4c0d07ef80252990 Mon Sep 17 00:00:00 2001 From: Pablo Deputter Date: Thu, 24 Sep 2026 12:00:27 +0200 Subject: [PATCH 3/3] put back `DATA_COLLECTION_USER_INFO_CASES` --- tests/integrations/pyramid/test_pyramid.py | 33 ++-------------------- 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/tests/integrations/pyramid/test_pyramid.py b/tests/integrations/pyramid/test_pyramid.py index 6b068acf32..57548b4620 100644 --- a/tests/integrations/pyramid/test_pyramid.py +++ b/tests/integrations/pyramid/test_pyramid.py @@ -15,6 +15,7 @@ from sentry_sdk.serializer import MAX_DATABAG_BREADTH from sentry_sdk.traces import SpanStatus from tests.conftest import unpack_werkzeug_response +from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES def hi(request): @@ -535,21 +536,7 @@ def test_span_origin( assert segment["attributes"]["sentry.origin"] == "auto.http.pyramid" -@pytest.mark.parametrize( - "init_kwargs, expect_user", - [ - pytest.param( - {"data_collection": {"user_info": True}}, - True, - id="data_collection_user_info_true", - ), - pytest.param( - {"data_collection": {"user_info": False}}, - False, - id="data_collection_user_info_false", - ), - ], -) +@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES) def test_span_sets_user_id_on_segment( sentry_init, pyramid_config, @@ -588,21 +575,7 @@ def authenticated_userid(self, request): assert "user.id" not in segment["attributes"] -@pytest.mark.parametrize( - "init_kwargs, expect_user", - [ - pytest.param( - {"data_collection": {"user_info": True}}, - True, - id="data_collection_user_info_true", - ), - pytest.param( - {"data_collection": {"user_info": False}}, - False, - id="data_collection_user_info_false", - ), - ], -) +@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES) def test_user_id_error_event_data_collection( sentry_init, pyramid_config,