Unable to get current request through class method while serving the app through other ASGI servers
Thirumalai opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Currently, Request.get_current() always throws ServerError when the Sanic app is served using a third-party ASGI server like Uvicorn.
Code snippet
import logging
from sanic import Sanic, ServerError, empty
from sanic.request import Request
logging.basicConfig(level=logging.DEBUG)
app = Sanic("SanicApp")
@app.route("/<path:path>")
async def hello(req: Request, path):
current_request = None
try:
current_request = Request.get_current()
except ServerError:
...
logging.info(f"{current_request=}")
return empty()
Expected Behavior
a valid Request object
How do you run Sanic?
Sanic CLI
Operating System
Mac
Sanic Version
23.3.0
Additional context
No response