Title: Strawberry integration crashes if no query is in request · Issue #2715 · getsentry/sentry-python · GitHub
Open Graph Title: Strawberry integration crashes if no query is in request · Issue #2715 · getsentry/sentry-python
X Title: Strawberry integration crashes if no query is in request · Issue #2715 · getsentry/sentry-python
Description: How do you use Sentry? Sentry Saas (sentry.io) Version 1.40.2 Steps to Reproduce Running an app with the StrawberryIntegration crashes if graphql endpoint is called with no query field in the input data. Place the attached litestar app c...
Open Graph Description: How do you use Sentry? Sentry Saas (sentry.io) Version 1.40.2 Steps to Reproduce Running an app with the StrawberryIntegration crashes if graphql endpoint is called with no query field in the input...
X Description: How do you use Sentry? Sentry Saas (sentry.io) Version 1.40.2 Steps to Reproduce Running an app with the StrawberryIntegration crashes if graphql endpoint is called with no query field in the input...
Opengraph URL: https://github.com/getsentry/sentry-python/issues/2715
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Strawberry integration crashes if no query is in request","articleBody":"### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Version\n\n1.40.2\n\n### Steps to Reproduce\n\nRunning an app with the StrawberryIntegration crashes if graphql endpoint is called with no `query` field in the input data.\r\n\r\n1. Place the attached litestar app code in `app.py` and install the requirements (sentry, strawberry graphql and litestar)\r\n2. Run the local server using `litestar run`\r\n3. Call the graphql endpoint using `curl -v -X POST -d \"{}\" -H \"Content-Type: application/json\" http://localhost:8000/graphql`\r\n4. This causes an exception to be raised, whereas if I comment out the sentry_sdk.init() line in the code, the \"expected\" result of a 400 Bad Request is returned. \r\n5. (The additional unwanted effect is that the 500 exception goes to sentry as an error in a production app - this is just a minimal reproduction).\r\n\r\napp.py:\r\n\r\n```\r\nimport logging\r\n\r\nfrom litestar import Litestar\r\nfrom litestar.logging import LoggingConfig\r\n\r\nimport sentry_sdk\r\nfrom sentry_sdk.integrations.strawberry import StrawberryIntegration\r\n\r\nimport strawberry\r\nfrom strawberry.litestar import make_graphql_controller\r\n\r\nsentry_sdk.init(integrations=[StrawberryIntegration(async_execution=True)])\r\n\r\n\r\n@strawberry.type\r\nclass Query:\r\n @strawberry.field\r\n def hello(self) -> str:\r\n return \"Hello World\"\r\n\r\n\r\nclass Schema(strawberry.Schema):\r\n async def execute(self, *args, **kwargs):\r\n try:\r\n return await super().execute(*args, **kwargs)\r\n except Exception as e:\r\n logging.getLogger(\"root\").exception(e)\r\n raise\r\n\r\n\r\nschema = Schema(Query)\r\n\r\nGraphQLController = make_graphql_controller(schema, path=\"/graphql\", debug=True)\r\n\r\napp = Litestar(\r\n route_handlers=[GraphQLController],\r\n logging_config=LoggingConfig(\r\n root={\"level\": logging.getLevelName(logging.INFO), \"handlers\": [\"console\"]},\r\n formatters={\r\n \"standard\": {\r\n \"format\": \"%(asctime)s - %(name)s - %(levelname)s - %(message)s\"\r\n }\r\n },\r\n ),\r\n)\r\n```\r\n\r\npip freeze:\r\n\r\n```\r\nanyio==4.2.0\r\ncertifi==2024.2.2\r\nclick==8.1.7\r\nEditorConfig==0.12.3\r\nFaker==23.0.0\r\nfast-query-parsers==1.0.3\r\ngraphql-core==3.2.3\r\nh11==0.14.0\r\nhttpcore==1.0.2\r\nhttptools==0.6.1\r\nhttpx==0.26.0\r\nidna==3.6\r\nJinja2==3.1.3\r\njsbeautifier==1.14.11\r\nlitestar==2.6.0\r\nmarkdown-it-py==3.0.0\r\nMarkupSafe==2.1.5\r\nmdurl==0.1.2\r\nmsgspec==0.18.6\r\nmultidict==6.0.5\r\npolyfactory==2.14.1\r\nPygments==2.17.2\r\npython-dateutil==2.8.2\r\npython-dotenv==1.0.1\r\nPyYAML==6.0.1\r\nrich==13.7.0\r\nrich-click==1.7.3\r\nsentry-sdk==1.40.2\r\nsix==1.16.0\r\nsniffio==1.3.0\r\nstrawberry-graphql==0.219.1\r\ntyping_extensions==4.9.0\r\nurllib3==2.2.0\r\nuvicorn==0.27.0.post1\r\nuvloop==0.19.0\r\nwatchfiles==0.21.0\r\nwebsockets==12.0\r\n```\r\n\n\n### Expected Result\n\n```\r\n\u003c HTTP/1.1 400 Bad Request\r\n\u003c date: Wed, 07 Feb 2024 13:52:14 GMT\r\n\u003c server: uvicorn\r\n\u003c content-type: text/plain; charset=utf-8\r\n\u003c content-length: 37\r\n\u003c \r\n* Connection #0 to host localhost left intact\r\nNo GraphQL query found in the request⏎ \r\n```\r\n\n\n### Actual Result\n\n```\r\n\u003c HTTP/1.1 500 Internal Server Error\r\n\u003c date: Wed, 07 Feb 2024 13:53:11 GMT\r\n\u003c server: uvicorn\r\n\u003c content-type: application/json\r\n\u003c content-length: 52\r\n\u003c \r\n* Connection #0 to host localhost left intact\r\n{\"status_code\":500,\"detail\":\"Internal Server Error\"}⏎ \r\n```\r\n\r\nOn the server console, there is a traceback from inside the strawberry integration:\r\n\r\n```\r\n2024-02-07 13:53:11,970 - root - ERROR - 'NoneType' object has no attribute 'strip'\r\nTraceback (most recent call last):\r\n File \"/Users/james/repos/sentrystrawberry/app.py\", line 25, in execute\r\n return await super().execute(*args, **kwargs)\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"/Users/james/.pyenv/versions/3.12.0/envs/mixcloud/lib/python3.12/site-packages/strawberry/schema/schema.py\", line 263, in execute\r\n result = await execute(\r\n ^^^^^^^^^^^^^^\r\n File \"/Users/james/.pyenv/versions/3.12.0/envs/mixcloud/lib/python3.12/site-packages/sentry_sdk/integrations/strawberry.py\", line 266, in _sentry_patched_execute_async\r\n result = await old_execute_async(*args, **kwargs)\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"/Users/james/.pyenv/versions/3.12.0/envs/mixcloud/lib/python3.12/site-packages/strawberry/schema/execute.py\", line 91, in execute\r\n async with extensions_runner.operation():\r\n File \"/Users/james/.pyenv/versions/3.12.0/envs/mixcloud/lib/python3.12/site-packages/strawberry/extensions/context.py\", line 191, in __aenter__\r\n await self.run_hooks_async()\r\n File \"/Users/james/.pyenv/versions/3.12.0/envs/mixcloud/lib/python3.12/site-packages/strawberry/extensions/context.py\", line 177, in run_hooks_async\r\n hook.initialized_hook.__next__() # type: ignore[union-attr]\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n File \"/Users/james/.pyenv/versions/3.12.0/envs/mixcloud/lib/python3.12/site-packages/sentry_sdk/integrations/strawberry.py\", line 148, in on_operation\r\n if self.execution_context.query.strip().startswith(\"mutation\"):\r\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\nAttributeError: 'NoneType' object has no attribute 'strip'\r\n```","author":{"url":"https://github.com/jthorniley","@type":"Person","name":"jthorniley"},"datePublished":"2024-02-07T14:02:37Z","url":"https://github.com/getsentry/sentry-python/issues/2715"}
| 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:0f98dc46-a791-e8d6-5d5a-a013d1f331fc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 92A4:36997C:211847:2E160F:6B00862B |
| html-safe-nonce | 0f136f8c85bbce5db1758a92231f51b97cbfa4e7237ba901f3a915a8f661ad3a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MkE0OjM2OTk3QzoyMTE4NDc6MkUxNjBGOjZCMDA4NjJCIiwidmlzaXRvcl9pZCI6Ijg0NTA0ODAzNDI4ODM2NjU0NTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ef14617b04929244ec8c00e8ebb47ccebb8eb7c7db2cc5f644a9ce52c24c972d |
| hovercard-subject-tag | issue:2123109584 |
| 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/2715/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6d6678d5cb706cf5848df5cc77c41e7ab25d603bcf2381e7a48fafbca11560f0/getsentry/sentry-python/issues/2715 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6d6678d5cb706cf5848df5cc77c41e7ab25d603bcf2381e7a48fafbca11560f0/getsentry/sentry-python/issues/2715 |
| og:image:alt | How do you use Sentry? Sentry Saas (sentry.io) Version 1.40.2 Steps to Reproduce Running an app with the StrawberryIntegration crashes if graphql endpoint is called with no query field in the input... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jthorniley |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4d3d8e50f02c1d7bf86d5acfa1d3bfe9366abd6528a6b429eb07a168429d2b61 |
| 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 | db758f8e02b8257935fb03edf81a3e76eb3abd11 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width