Title: gql: execute() leaves its event processor on the isolation scope, so later unrelated errors are reported as GraphQL requests · Issue #8262 · getsentry/sentry-python · GitHub
Open Graph Title: gql: execute() leaves its event processor on the isolation scope, so later unrelated errors are reported as GraphQL requests · Issue #8262 · getsentry/sentry-python
X Title: gql: execute() leaves its event processor on the isolation scope, so later unrelated errors are reported as GraphQL requests · Issue #8262 · getsentry/sentry-python
Description: How do you use Sentry? Sentry Saas (sentry.io) Version master (860a060), gql 4.4.0 Steps to Reproduce sentry_patched_execute adds an event processor to the isolation scope on every Client.execute() and never removes it: scope = sentry_sd...
Open Graph Description: How do you use Sentry? Sentry Saas (sentry.io) Version master (860a060), gql 4.4.0 Steps to Reproduce sentry_patched_execute adds an event processor to the isolation scope on every Client.execute()...
X Description: How do you use Sentry? Sentry Saas (sentry.io) Version master (860a060), gql 4.4.0 Steps to Reproduce sentry_patched_execute adds an event processor to the isolation scope on every Client.execute()...
Opengraph URL: https://github.com/getsentry/sentry-python/issues/8262
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"gql: execute() leaves its event processor on the isolation scope, so later unrelated errors are reported as GraphQL requests","articleBody":"### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Version\n\nmaster (860a060), gql 4.4.0\n\n### Steps to Reproduce\n\n`sentry_patched_execute` adds an event processor to the isolation scope on every `Client.execute()` and never removes it:\n\n```python\nscope = sentry_sdk.get_isolation_scope()\nscope.add_event_processor(_make_gql_event_processor(self, document))\n```\n\ngql is a client, so it's often called outside a per-request isolation scope (scripts, workers, task loops), or many times inside one request. The processors outlive the query and apply to every later event on that scope.\n\n```python\nimport sentry_sdk\nfrom gql import Client, gql\nfrom gql.transport.requests import RequestsHTTPTransport\nfrom sentry_sdk.integrations.gql import GQLIntegration\n\nsentry_sdk.init(dsn=..., integrations=[GQLIntegration()], send_default_pii=True)\nclient = Client(transport=RequestsHTTPTransport(url=\"http://example.com/graphql\"))\n\nfor i in range(100):\n client.execute(gql(\"query Q%d { example }\" % i)) # all succeed\n\n# later, unrelated to GraphQL\ntry:\n raise ValueError(\"unrelated error\")\nexcept ValueError:\n sentry_sdk.capture_exception()\n```\n\nFull repro (HTTP mocked with `responses`, events captured from a custom transport): https://github.com/Mohil-Ahuja/ci-scratch/blob/main/repro/gql_processors.py, run output: https://github.com/Mohil-Ahuja/ci-scratch/actions/runs/42837565235\n\n### Expected Result\n\nThe unrelated `ValueError` has no GraphQL request data, and `contexts.response.type` is `\"response\"` on gql error events.\n\n### Actual Result\n\n1. **Unrelated errors are tagged as GraphQL requests.** The `ValueError` above is sent with the last query attached:\n\n ```json\n \"request\": {\"api_target\": \"graphql\", \"method\": \"POST\", \"url\": \"http://example.com/graphql\",\n \"data\": {\"query\": \"query Q99 {\\n example\\n}\", \"variables\": null, \"operationName\": \"Q99\"}}\n ```\n\n2. **Other processors on the scope get wiped.** Once a scope has more than 20 processors, `Scope.add_event_processor` clears all of them. So 21 gql calls in one request remove processors added by the app or other integrations. In the repro, a processor added to the same isolation scope before 21 queries is gone afterwards, and the next error event is missing its tag.\n\n3. **`contexts.response.type` is a self-reference.** Both branches of the processor do `response.update({\"data\": ..., \"type\": response})`, which sets `type` to the dict itself, so it's serialized as `\"\u003ccyclic>\"`:\n\n ```json\n \"response\": {\"data\": {\"errors\": [{\"message\": \"boom\"}]}, \"type\": \"\u003ccyclic>\"}\n ```\n\nPossible fix: fork a scope around `real_execute` (`with sentry_sdk.new_scope() as scope:`) and add the processor there, so it only applies to events captured during the query (including the `TransportQueryError` event), and set `\"type\": \"response\"`. Happy to open a PR with tests.\n","author":{"url":"https://github.com/Mohil-Ahuja","@type":"Person","name":"Mohil-Ahuja"},"datePublished":"2026-11-12T13:08:44Z","url":"https://github.com/getsentry/sentry-python/issues/8262"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:985b82a4-fa7c-48d7-bf2b-f64ee2906d3a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D132:428E1:2A7E54:388B12:6B009D55 |
| html-safe-nonce | 97676f68079ea7cb64181c14c778bfc46647f2e152a800cfd611ffc76943094b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTMyOjQyOEUxOjJBN0U1NDozODhCMTI6NkIwMDlENTUiLCJ2aXNpdG9yX2lkIjoiNjY3NTU1NTMwNTAzMzYwNDQzOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6cf35af7fcb2ee50054068407555a80a35495f2fa4c106cfac05bc73c1053606 |
| hovercard-subject-tag | issue:6350485245 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-python/8262/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e8411f0111a02091325cfc8c02d687a49f5a8ad01de524932ce7baa307e6458c/getsentry/sentry-python/issues/8262 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e8411f0111a02091325cfc8c02d687a49f5a8ad01de524932ce7baa307e6458c/getsentry/sentry-python/issues/8262 |
| og:image:alt | How do you use Sentry? Sentry Saas (sentry.io) Version master (860a060), gql 4.4.0 Steps to Reproduce sentry_patched_execute adds an event processor to the isolation scope on every Client.execute()... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Mohil-Ahuja |
| hostname | github.com |
| expected-hostname | github.com |
| None | 52c95ce7e48016ae14399656b4ee812462b6f1fa28c5008c8394da64794c00b8 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-python git https://github.com/getsentry/sentry-python.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 137814779 |
| octolytics-dimension-repository_nwo | getsentry/sentry-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 137814779 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1c9ddec8215f9a94e295c8310c3579b9c54ba31a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width