async def dispatch( self, request: Request, call_next: RequestResponseEndpoint, ): request_id = str(uuid4()) token = session_context.set(request_id) try: response = await call_next(request) except Exception as e: session.rollback() raise e finally: session.remove() session_context.reset(token) return response
async def remove_session(request: Request, call_next): response = await call_next(request) session.remove() return response
def after_request(response: Response) -> Response: session.remove() return response