Skip to content

Commit

Permalink
Fixed problem with broken response and python-multipart (#1516)
Browse files Browse the repository at this point in the history
* Fixed problem with broken response when only FastApiIntegration() is enabled.
* Fixed problem when python-multipart is not installed
  • Loading branch information
antonpirker committed Jul 22, 2022
1 parent 90b7f1b commit 9857bc9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions sentry_sdk/integrations/fastapi.py
Expand Up @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion 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
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 9857bc9

Please sign in to comment.