Skip to content

Starlette integration requires python-multipart #1515

@matyasrichter

Description

@matyasrichter

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

Metadata

Metadata

Assignees

Labels

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions