From 73c0134868f73386992329eaee0828164f25da4a Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Tue, 3 Sep 2024 13:53:32 +0200 Subject: [PATCH 1/2] feat(strawberry): Support Strawberry 0.239.2 Update our Strawberry integration to support the latest versions of Strawberry, following upstream breaking changes which caused our tests to fail. Closes #3490 Co-authored-by: Ivana Kellyer --- sentry_sdk/integrations/strawberry.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sentry_sdk/integrations/strawberry.py b/sentry_sdk/integrations/strawberry.py index 6070ac3252..08935e62ef 100644 --- a/sentry_sdk/integrations/strawberry.py +++ b/sentry_sdk/integrations/strawberry.py @@ -41,10 +41,10 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - from typing import Any, Callable, Generator, List, Optional + from typing import Any, Callable, Generator, List, Optional, Union from graphql import GraphQLError, GraphQLResolveInfo # type: ignore from strawberry.http import GraphQLHTTPResponse - from strawberry.types import ExecutionContext, ExecutionResult # type: ignore + from strawberry.types import ExecutionContext, ExecutionResult, SubscriptionExecutionResult # type: ignore from sentry_sdk._types import Event, EventProcessor @@ -291,13 +291,13 @@ def _patch_execute(): old_execute_sync = strawberry_schema.execute_sync async def _sentry_patched_execute_async(*args, **kwargs): - # type: (Any, Any) -> ExecutionResult + # type: (Any, Any) -> Union[ExecutionResult, SubscriptionExecutionResult] result = await old_execute_async(*args, **kwargs) if sentry_sdk.get_client().get_integration(StrawberryIntegration) is None: return result - if "execution_context" in kwargs and result.errors: + if "execution_context" in kwargs: scope = sentry_sdk.get_isolation_scope() event_processor = _make_request_event_processor(kwargs["execution_context"]) scope.add_event_processor(event_processor) From ff763e6055eff97c5ecad6db02f024fa875332c0 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Tue, 3 Sep 2024 16:17:19 +0200 Subject: [PATCH 2/2] ref(strawberry): Make sync `execute` consistent --- sentry_sdk/integrations/strawberry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/strawberry.py b/sentry_sdk/integrations/strawberry.py index 08935e62ef..ac792c8612 100644 --- a/sentry_sdk/integrations/strawberry.py +++ b/sentry_sdk/integrations/strawberry.py @@ -309,7 +309,7 @@ def _sentry_patched_execute_sync(*args, **kwargs): # type: (Any, Any) -> ExecutionResult result = old_execute_sync(*args, **kwargs) - if "execution_context" in kwargs and result.errors: + if "execution_context" in kwargs: scope = sentry_sdk.get_isolation_scope() event_processor = _make_request_event_processor(kwargs["execution_context"]) scope.add_event_processor(event_processor)