Jaymon / endpoints

Lightweight REST api backend framework that automatically maps urls to python modules and classes
MIT License
29 stars 10 forks source link

Should call.Param.handle be async? #137

Closed Jaymon closed 6 months ago

Jaymon commented 6 months ago

I've extended call.Param in another project and I made my new class have an async handle method, but that meant I needed to override decorators.call.param.handle_param to use await. If Param.handle was already async then I wouldn't have had to change the param decorator at all except to set param_class

Jaymon commented 6 months ago

So I just ran into a subtle bug (not so subtle after I finally figured it out), I basically had a setup like this:

class Foo(Controller):
    @child_of_param("child_variable_name")
    @param("variable_name")
    def POST(self, **kwargs): pass

So when endpoints actually handles the decorators, it's the @param call that runs all the decorators and @child_of_param uses an async param_class.handle method. That caused the handling to fail because the internal param was never awaited. That's because @param just called param.handle in param.handle_param.

There are a few fixes for this, one of them is to modify param.handle_param to check if the passed in param has an async handle method and await it if it does. I can also have the param keep track of the actual decorators and call their methods instead of its own.

In the end, I think both of these should be done, so decorators.call.param should be modified to: