Robyn icon indicating copy to clipboard operation
Robyn copied to clipboard

'NoneType' object has no attribute 'queries'

Open T-baby opened this issue 2 years ago β€’ 4 comments

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

  1. My code:
@app.before_request()
async def before_req(request):
    print("before_request")
    print(request)
    return
  1. Access any url.

Your operating system

MacOS

Your Python version (python --version)

3.11

Your Robyn version

latest

Additional Info

No response

T-baby avatar Jul 27 '23 11:07 T-baby

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?

IdoKendo avatar Jul 27 '23 12:07 IdoKendo

It works. I feel like the before_request shouldn't force a return or have a friendlier error message.

T-baby avatar Jul 28 '23 01:07 T-baby

@T-baby , I agree with you 😊 Let's keep the issue open!

sansyrox avatar Jul 28 '23 09:07 sansyrox

And thanks for the triage @IdoKendo 😊

sansyrox avatar Jul 28 '23 09:07 sansyrox

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 πŸ˜„

sansyrox avatar Apr 12 '24 22:04 sansyrox