Skip to content

Commit 9538434

Browse files
fix(strawberry): Prevent AttributeError on missing graphql_span (#4991)
1 parent 48dc566 commit 9538434

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

sentry_sdk/integrations/strawberry.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,12 @@ def on_operation(self) -> "Generator[None, None, None]":
202202
self.graphql_span.__exit__(None, None, None)
203203

204204
def on_validate(self) -> "Generator[None, None, None]":
205-
self.validation_span = self.graphql_span.start_child(
205+
graphql_span = getattr(self, "graphql_span", None)
206+
if not graphql_span:
207+
yield
208+
return
209+
210+
self.validation_span = graphql_span.start_child(
206211
op=OP.GRAPHQL_VALIDATE,
207212
name="validation",
208213
origin=StrawberryIntegration.origin,
@@ -213,7 +218,12 @@ def on_validate(self) -> "Generator[None, None, None]":
213218
self.validation_span.finish()
214219

215220
def on_parse(self) -> "Generator[None, None, None]":
216-
self.parsing_span = self.graphql_span.start_child(
221+
graphql_span = getattr(self, "graphql_span", None)
222+
if not graphql_span:
223+
yield
224+
return
225+
226+
self.parsing_span = graphql_span.start_child(
217227
op=OP.GRAPHQL_PARSE,
218228
name="parsing",
219229
origin=StrawberryIntegration.origin,
@@ -256,9 +266,13 @@ async def resolve(
256266
if self.should_skip_tracing(_next, info):
257267
return await self._resolve(_next, root, info, *args, **kwargs)
258268

269+
graphql_span = getattr(self, "graphql_span", None)
270+
if not graphql_span:
271+
return await self._resolve(_next, root, info, *args, **kwargs)
272+
259273
field_path = "{}.{}".format(info.parent_type, info.field_name)
260274

261-
with self.graphql_span.start_child(
275+
with graphql_span.start_child(
262276
op=OP.GRAPHQL_RESOLVE,
263277
name="resolving {}".format(field_path),
264278
origin=StrawberryIntegration.origin,
@@ -283,9 +297,13 @@ def resolve(
283297
if self.should_skip_tracing(_next, info):
284298
return _next(root, info, *args, **kwargs)
285299

300+
graphql_span = getattr(self, "graphql_span", None)
301+
if not graphql_span:
302+
return _next(root, info, *args, **kwargs)
303+
286304
field_path = "{}.{}".format(info.parent_type, info.field_name)
287305

288-
with self.graphql_span.start_child(
306+
with graphql_span.start_child(
289307
op=OP.GRAPHQL_RESOLVE,
290308
name="resolving {}".format(field_path),
291309
origin=StrawberryIntegration.origin,

0 commit comments

Comments
 (0)