Skip to content

Commit ef17686

Browse files
committed
Merge branch 'master' into major/3.0
2 parents 1df5669 + 4b701c0 commit ef17686

6 files changed

Lines changed: 39 additions & 17 deletions

File tree

‎.github/workflows/changelog-preview.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ permissions:
1515

1616
jobs:
1717
changelog-preview:
18-
uses: getsentry/craft/.github/workflows/changelog-preview.yml@0da9309228741a4c300d3c87ed7dcafa8f703525 # 3.12.0
18+
uses: getsentry/craft/.github/workflows/changelog-preview.yml@6a763ab19893ff85c830b709fb5633a61924945e # 3.12.2
1919
secrets:
2020
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎.github/workflows/release.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
token: ${{ steps.token.outputs.token }}
3232
fetch-depth: 0
3333
- name: Prepare release
34-
uses: getsentry/craft@0da9309228741a4c300d3c87ed7dcafa8f703525 # 3.12.0
34+
uses: getsentry/craft@6a763ab19893ff85c830b709fb5633a61924945e # 3.12.2
3535
env:
3636
GITHUB_TOKEN: ${{ steps.token.outputs.token }}
3737
with:

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,4 @@ When integrating with a package:
9898
- Avoid testing things that can't realistically break.
9999
- Avoid duplicating tests (extend an existing one or use `parametrize`).
100100
- Assert on what Sentry captures with `capture_events`/`capture_items`.
101+
- When adding regression tests, they must fail without the fix. Verify that that's the case before committing them.

‎sentry_sdk/integrations/gql.py‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,24 @@ def sentry_patched_execute(
138138
*args: "Any",
139139
**kwargs: "Any",
140140
) -> "Any":
141-
scope = sentry_sdk.get_isolation_scope()
142-
# document is a gql.GraphQLRequest with gql v4.0.0.
143-
scope.add_event_processor(_make_gql_event_processor(self, document))
144-
145-
try:
141+
# Add the processor to a scope that lives only as long as this
142+
# query, so that it doesn't apply to unrelated events captured
143+
# later on the same isolation scope.
144+
with sentry_sdk.new_scope() as scope:
146145
# document is a gql.GraphQLRequest with gql v4.0.0.
147-
return real_execute(self, document, *args, **kwargs)
148-
except TransportQueryError as e:
149-
event, hint = event_from_exception(
150-
e,
151-
mechanism={"type": "gql", "handled": False},
152-
)
146+
scope.add_event_processor(_make_gql_event_processor(self, document))
147+
148+
try:
149+
# document is a gql.GraphQLRequest with gql v4.0.0.
150+
return real_execute(self, document, *args, **kwargs)
151+
except TransportQueryError as e:
152+
event, hint = event_from_exception(
153+
e,
154+
mechanism={"type": "gql", "handled": False},
155+
)
153156

154-
sentry_sdk.capture_event(event, hint)
155-
raise e
157+
sentry_sdk.capture_event(event, hint)
158+
raise e
156159

157160
gql.Client.execute = sentry_patched_execute
158161

@@ -192,7 +195,7 @@ def processor(event: "Event", hint: "dict[str, Any]") -> "Event":
192195
response.update(
193196
{
194197
"data": {"errors": errors},
195-
"type": response,
198+
"type": "response",
196199
}
197200
)
198201

‎sentry_sdk/transport.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def __init__(self: "Self", options: "Dict[str, Any]") -> None:
196196
self._worker = self._create_worker(options)
197197
self._auth = self.parsed_dsn.to_auth("sentry.python/%s" % VERSION)
198198
self._disabled_until: "Dict[Optional[EventDataCategory], datetime]" = {}
199-
# We only use this Retry() class for the `get_retry_after` method it exposes
199+
# We only use this Retry() class for the `parse_retry_after` method it exposes
200200
self._retry = urllib3.util.Retry()
201201
self._discarded_events: "DefaultDict[Tuple[EventDataCategory, str], int]" = (
202202
defaultdict(int)

‎tests/integrations/gql/test_gql.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from gql.transport.exceptions import TransportQueryError
77
from gql.transport.requests import RequestsHTTPTransport
88

9+
import sentry_sdk
910
from sentry_sdk.integrations.gql import GQLIntegration
1011
from sentry_sdk.utils import parse_version
1112

@@ -183,6 +184,7 @@ def test_real_gql_request_with_error_data_collection(
183184
assert "data" in event["request"]
184185
assert "query" in event["request"]["data"]
185186
assert "response" in event["contexts"]
187+
assert event["contexts"]["response"]["type"] == "response"
186188
else:
187189
assert "data" not in event["request"]
188190
assert "response" not in event["contexts"]
@@ -290,3 +292,19 @@ def test_transport_url_is_sanitized(
290292
assert event["request"].get("query_string") == expected_query_string
291293
assert "password" not in str(event["request"])
292294
assert "secret" not in str(event["request"])
295+
296+
297+
def test_event_processor_does_not_outlive_query(sentry_init, capture_events):
298+
"""
299+
Events captured after a query has finished must not get the query's
300+
request data.
301+
"""
302+
sentry_init(integrations=[GQLIntegration()])
303+
events = capture_events()
304+
305+
_execute_mock_query({"data": {"example": "This is the example"}})
306+
sentry_sdk.capture_message("unrelated")
307+
308+
(event,) = events
309+
assert "request" not in event
310+
assert "response" not in event.get("contexts", {})

0 commit comments

Comments
 (0)