Skip to content

Commit 9857bc9

Browse files
authored
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
1 parent 90b7f1b commit 9857bc9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

sentry_sdk/integrations/fastapi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ async def __call__(self, scope, receive, send):
9696
hub = Hub.current
9797
integration = hub.get_integration(FastApiIntegration)
9898
if integration is None:
99+
await self.app(scope, receive, send)
99100
return
100101

101102
with hub.configure_scope() as sentry_scope:

sentry_sdk/integrations/starlette.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import absolute_import
22

3-
43
from sentry_sdk._compat import iteritems
54
from sentry_sdk._types import MYPY
65
from sentry_sdk.hub import Hub, _should_send_default_pii
@@ -41,6 +40,12 @@
4140
# Startlette 0.19.1
4241
from starlette.exceptions import ExceptionMiddleware # type: ignore
4342

43+
try:
44+
# Optional dependency of Starlette to parse form data.
45+
import multipart # type: ignore # noqa: F401
46+
except ImportError:
47+
multipart = None
48+
4449

4550
_DEFAULT_TRANSACTION_NAME = "generic Starlette request"
4651

@@ -339,6 +344,9 @@ async def form(self):
339344
curl -X POST http://localhost:8000/upload/somethign -H "Content-Type: application/x-www-form-urlencoded" -d "username=kevin&password=welcome123"
340345
curl -X POST http://localhost:8000/upload/somethign -F username=Julian -F password=hello123
341346
"""
347+
if multipart is None:
348+
return None
349+
342350
return await self.request.form()
343351

344352
def is_json(self):
@@ -423,6 +431,7 @@ async def __call__(self, scope, receive, send):
423431
hub = Hub.current
424432
integration = hub.get_integration(StarletteIntegration)
425433
if integration is None:
434+
await self.app(scope, receive, send)
426435
return
427436

428437
with hub.configure_scope() as sentry_scope:

0 commit comments

Comments
 (0)