sentry-python icon indicating copy to clipboard operation
sentry-python copied to clipboard

Starlette integration requires python-multipart

Open matyasrichter opened this issue 4 years ago • 5 comments

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.8.0

Steps to Reproduce

Using the Starlette/FastAPI integration while python-multipart isn't installed raises an exception. It's an optional dependency for Starlette, but not optional for sentry-sdk.

sentry_sdk.init(
    dsn=settings.SENTRY_DSN,
    integrations=[StarletteIntegration(), FastApiIntegration()],
)

This can be fixed by gathering form data conditionally.

Expected Result

No exception.

Actual Result

Sending any request, even a GET, raises an exceptions, here's the relevant part of the stacktrace:

.venv/lib/python3.10/site-packages/fastapi/applications.py:269: in __call__
    await super().__call__(scope, receive, send)
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py:268: in _sentry_patched_asgi_app
    return await middleware(scope, receive, send)
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py:126: in _run_asgi3
    return await self._run_app(scope, lambda: self.app(scope, receive, send))
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py:176: in _run_app
    raise exc from None
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py:171: in _run_app
    return await callback()
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py:268: in _sentry_patched_asgi_app
    return await middleware(scope, receive, send)
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py:126: in _run_asgi3
    return await self._run_app(scope, lambda: self.app(scope, receive, send))
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py:137: in _run_app
    raise exc from None
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/asgi.py:134: in _run_app
    return await callback()
.venv/lib/python3.10/site-packages/starlette/applications.py:124: in __call__
    await self.middleware_stack(scope, receive, send)
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/fastapi.py:122: in __call__
    await self.app(scope, receive, send)
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py:432: in __call__
    info = await extractor.extract_request_info()
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py:305: in extract_request_info
    parsed_body = await self.parsed_body()
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py:363: in parsed_body
    form = await self.form()
.venv/lib/python3.10/site-packages/sentry_sdk/integrations/starlette.py:342: in form
    return await self.request.form()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <starlette.requests.Request object at 0x7ff9da7f7610>
    async def form(self) -> FormData:
        if not hasattr(self, "_form"):
>           assert (
                parse_options_header is not None
            ), "The `python-multipart` library must be installed to use form parsing."
E           AssertionError: The `python-multipart` library must be installed to use form parsing.
.venv/lib/python3.10/site-packages/starlette/requests.py:247: AssertionError

matyasrichter avatar Jul 22 '22 07:07 matyasrichter

Hey @matyasrichter thanks for reporting this! I will have a look in the afternoon at this!

antonpirker avatar Jul 22 '22 09:07 antonpirker

thanks for the fast response ,, good to know the PR is already open ,, ^_^

MrSalman333 avatar Jul 22 '22 17:07 MrSalman333

@antonpirker Any estimate on when this could make it into a release? :pray:

matyasrichter avatar Jul 26 '22 06:07 matyasrichter

@matyasrichter I think the problem is already solved in the release 1.9.0 :)

https://github.com/getsentry/sentry-python/tree/1.9.0

juanbenitopr avatar Jul 29 '22 08:07 juanbenitopr

yes, this is fixed, closing

sl0thentr0py avatar Jul 29 '22 09:07 sl0thentr0py