Open cancan101 opened 3 years ago
The current middleware subclasses BaseHTTPMiddleware which per https://github.com/encode/starlette/issues/919 and https://github.com/tiangolo/fastapi/issues/2086 will cause all background tasks to run before the response is sent. Better would be to not subclass BaseHTTPMiddleware.
BaseHTTPMiddleware
Instead the class would look like:
class DBSessionMiddleware: def __init__(self, app....) .... async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: with db(): await self.app(scope, receive, send)
The current middleware subclasses
BaseHTTPMiddleware
which per https://github.com/encode/starlette/issues/919 and https://github.com/tiangolo/fastapi/issues/2086 will cause all background tasks to run before the response is sent. Better would be to not subclassBaseHTTPMiddleware
.Instead the class would look like: