Skip to content

Commit f2a9f38

Browse files
committed
fix(strawberry): Remove autodetection, always use sync extension
1 parent 086197f commit f2a9f38

File tree

2 files changed

+15
-54
lines changed

2 files changed

+15
-54
lines changed

sentry_sdk/integrations/strawberry.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import functools
22
import hashlib
3+
import warnings
34
from inspect import isawaitable
45

56
import sentry_sdk
@@ -98,13 +99,10 @@ def _sentry_patched_schema_init(self, *args, **kwargs):
9899
if integration.async_execution is not None:
99100
should_use_async_extension = integration.async_execution
100101
else:
101-
# try to figure it out ourselves
102-
should_use_async_extension = _guess_if_using_async(extensions)
103-
104-
logger.info(
105-
"Assuming strawberry is running %s. If not, initialize it as StrawberryIntegration(async_execution=%s).",
106-
"async" if should_use_async_extension else "sync",
107-
"False" if should_use_async_extension else "True",
102+
# use the sync extension by default
103+
warnings.warn(
104+
"Assuming strawberry is running sync. If not, initialize the integration as StrawberryIntegration(async_execution=True).",
105+
stacklevel=2,
108106
)
109107

110108
# remove the built in strawberry sentry extension, if present
@@ -379,15 +377,3 @@ def inner(event, hint):
379377
return event
380378

381379
return inner
382-
383-
384-
def _guess_if_using_async(extensions):
385-
# type: (List[SchemaExtension]) -> bool
386-
if StrawberrySentryAsyncExtension in extensions:
387-
return True
388-
elif StrawberrySentrySyncExtension in extensions:
389-
return False
390-
391-
return bool(
392-
{"starlette", "starlite", "litestar", "fastapi"} & set(_get_installed_modules())
393-
)

tests/integrations/strawberry/test_strawberry.py

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -103,49 +103,24 @@ def create_app(schema):
103103
def test_async_execution_uses_async_extension(sentry_init):
104104
sentry_init(integrations=[StrawberryIntegration(async_execution=True)])
105105

106-
with mock.patch(
107-
"sentry_sdk.integrations.strawberry._get_installed_modules",
108-
return_value={"flask": "2.3.3"},
109-
):
110-
# actual installed modules should not matter, the explicit option takes
111-
# precedence
112-
schema = strawberry.Schema(Query)
113-
assert SentryAsyncExtension in schema.extensions
106+
schema = strawberry.Schema(Query)
107+
assert SentryAsyncExtension in schema.extensions
108+
assert SentrySyncExtension not in schema.extensions
114109

115110

116111
def test_sync_execution_uses_sync_extension(sentry_init):
117112
sentry_init(integrations=[StrawberryIntegration(async_execution=False)])
118113

119-
with mock.patch(
120-
"sentry_sdk.integrations.strawberry._get_installed_modules",
121-
return_value={"fastapi": "0.103.1", "starlette": "0.27.0"},
122-
):
123-
# actual installed modules should not matter, the explicit option takes
124-
# precedence
125-
schema = strawberry.Schema(Query)
126-
assert SentrySyncExtension in schema.extensions
127-
128-
129-
def test_infer_execution_type_from_installed_packages_async(sentry_init):
130-
sentry_init(integrations=[StrawberryIntegration()])
131-
132-
with mock.patch(
133-
"sentry_sdk.integrations.strawberry._get_installed_modules",
134-
return_value={"fastapi": "0.103.1", "starlette": "0.27.0"},
135-
):
136-
schema = strawberry.Schema(Query)
137-
assert SentryAsyncExtension in schema.extensions
114+
schema = strawberry.Schema(Query)
115+
assert SentrySyncExtension in schema.extensions
116+
assert SentryAsyncExtension not in schema.extensions
138117

139118

140-
def test_infer_execution_type_from_installed_packages_sync(sentry_init):
119+
def test_use_sync_extension_if_not_specified(sentry_init):
141120
sentry_init(integrations=[StrawberryIntegration()])
142-
143-
with mock.patch(
144-
"sentry_sdk.integrations.strawberry._get_installed_modules",
145-
return_value={"flask": "2.3.3"},
146-
):
147-
schema = strawberry.Schema(Query)
148-
assert SentrySyncExtension in schema.extensions
121+
schema = strawberry.Schema(Query)
122+
assert SentrySyncExtension in schema.extensions
123+
assert SentryAsyncExtension not in schema.extensions
149124

150125

151126
@pytest.mark.skipif(

0 commit comments

Comments
 (0)