From 9857bc97ff5f8c34cbc667f7bfde35323f0531a9 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Fri, 22 Jul 2022 20:01:05 +0200 Subject: [PATCH] Fixed problem with broken response and python-multipart (#1516) * Fixed problem with broken response when only FastApiIntegration() is enabled. * Fixed problem when python-multipart is not installed --- sentry_sdk/integrations/fastapi.py | 1 + sentry_sdk/integrations/starlette.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/fastapi.py b/sentry_sdk/integrations/fastapi.py index c5fa4e84e2..2ec4800b19 100644 --- a/sentry_sdk/integrations/fastapi.py +++ b/sentry_sdk/integrations/fastapi.py @@ -96,6 +96,7 @@ async def __call__(self, scope, receive, send): hub = Hub.current integration = hub.get_integration(FastApiIntegration) if integration is None: + await self.app(scope, receive, send) return with hub.configure_scope() as sentry_scope: diff --git a/sentry_sdk/integrations/starlette.py b/sentry_sdk/integrations/starlette.py index 5fa8719e75..e2c5366ae2 100644 --- a/sentry_sdk/integrations/starlette.py +++ b/sentry_sdk/integrations/starlette.py @@ -1,6 +1,5 @@ from __future__ import absolute_import - from sentry_sdk._compat import iteritems from sentry_sdk._types import MYPY from sentry_sdk.hub import Hub, _should_send_default_pii @@ -41,6 +40,12 @@ # Startlette 0.19.1 from starlette.exceptions import ExceptionMiddleware # type: ignore +try: + # Optional dependency of Starlette to parse form data. + import multipart # type: ignore # noqa: F401 +except ImportError: + multipart = None + _DEFAULT_TRANSACTION_NAME = "generic Starlette request" @@ -339,6 +344,9 @@ async def form(self): curl -X POST http://localhost:8000/upload/somethign -H "Content-Type: application/x-www-form-urlencoded" -d "username=kevin&password=welcome123" curl -X POST http://localhost:8000/upload/somethign -F username=Julian -F password=hello123 """ + if multipart is None: + return None + return await self.request.form() def is_json(self): @@ -423,6 +431,7 @@ async def __call__(self, scope, receive, send): hub = Hub.current integration = hub.get_integration(StarletteIntegration) if integration is None: + await self.app(scope, receive, send) return with hub.configure_scope() as sentry_scope: