Skip to content

Commit 25e666f

Browse files
feat(strawberry): Support Strawberry 0.239.1
1 parent cd15bff commit 25e666f

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

sentry_sdk/integrations/strawberry.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
logger,
1515
package_version,
1616
_get_installed_modules,
17+
async_any,
1718
)
1819

1920
try:
@@ -35,16 +36,17 @@
3536
SentryTracingExtensionSync as StrawberrySentrySyncExtension,
3637
)
3738
from strawberry.http import async_base_view, sync_base_view # type: ignore
39+
from strawberry.types import ExecutionContext, ExecutionResult # type: ignore[import-not-found]
3840
except ImportError:
3941
raise DidNotEnable("strawberry-graphql is not installed")
4042

4143
from typing import TYPE_CHECKING
4244

4345
if TYPE_CHECKING:
44-
from typing import Any, Callable, Generator, List, Optional
46+
from typing import Any, Callable, Generator, List, Optional, Union
4547
from graphql import GraphQLError, GraphQLResolveInfo # type: ignore
4648
from strawberry.http import GraphQLHTTPResponse
47-
from strawberry.types import ExecutionContext, ExecutionResult # type: ignore
49+
from strawberry.types import SubscriptionExecutionResult
4850
from sentry_sdk._types import Event, EventProcessor
4951

5052

@@ -291,13 +293,17 @@ def _patch_execute():
291293
old_execute_sync = strawberry_schema.execute_sync
292294

293295
async def _sentry_patched_execute_async(*args, **kwargs):
294-
# type: (Any, Any) -> ExecutionResult
296+
# type: (Any, Any) -> Union[ExecutionResult, SubscriptionExecutionResult]
295297
result = await old_execute_async(*args, **kwargs)
296298

297299
if sentry_sdk.get_client().get_integration(StrawberryIntegration) is None:
298300
return result
299301

300-
if "execution_context" in kwargs and result.errors:
302+
if "execution_context" in kwargs and (
303+
result.errors
304+
if isinstance(result, ExecutionResult)
305+
else await async_any(r.errors async for r in result)
306+
):
301307
scope = sentry_sdk.get_isolation_scope()
302308
event_processor = _make_request_event_processor(kwargs["execution_context"])
303309
scope.add_event_processor(event_processor)

sentry_sdk/utils.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from typing import TYPE_CHECKING
3232

3333
if TYPE_CHECKING:
34-
from collections.abc import Awaitable
34+
from collections.abc import Awaitable, AsyncIterable, AsyncIterator
3535

3636
from types import FrameType, TracebackType
3737
from typing import (
@@ -1910,3 +1910,17 @@ def get_current_thread_meta(thread=None):
19101910

19111911
# we've tried everything, time to give up
19121912
return None, None
1913+
1914+
1915+
if TYPE_CHECKING:
1916+
A = TypeVar("A")
1917+
1918+
1919+
async def async_any(async_iterable):
1920+
# type: (Union[AsyncIterable[A], AsyncIterator[A]]) -> bool
1921+
"""Given an async iterable, return True if any of the items are truthy, otherwise False."""
1922+
async for item in async_iterable:
1923+
if item:
1924+
return True
1925+
1926+
return False

0 commit comments

Comments
 (0)