Robyn
Robyn copied to clipboard
'NoneType' object has no attribute 'queries'
Bug Description
If I use middleware that adds a global before_request, this will get an exception.
ERROR:robyn.server:Error while executing before middleware function for endpoint /: 'NoneType' object has no attribute 'queries'
Steps to Reproduce
- My codeοΌ
@app.before_request()
async def before_req(request):
print("before_request")
print(request)
return
- Access any url.
Your operating system
MacOS
Your Python version (python --version)
3.11
Your Robyn version
latest
Additional Info
No response
Hey @T-baby π
The before_request decorator requires the function it wraps to return a Request - Since you are returning None it fails.
For an immediate fix, you can just add return request at the end instead of a blank return.
@sansyrox Maybe the docs needs to reflect that, or the behavior needs to handle cases that before_request wrapped function doesn't return a Request, WDYT?
It works. I feel like the before_request shouldn't force a return or have a friendlier error message.
@T-baby , I agree with you π Let's keep the issue open!
And thanks for the triage @IdoKendo π
Hey @T-baby π
This is the expected behavior, however, the response should be implicitly casted. https://github.com/sparckles/Robyn/issues/793
Adding documentation for this behaviour tho.
Do let me know if you have any more suggestions/questions π