flask-restx icon indicating copy to clipboard operation
flask-restx copied to clipboard

Make api.route() work with Flask 2.x async endpoints

Open JesseDeLoore opened this issue 3 years ago • 8 comments

If you add a resource to your API with the decorator your actual functions get wrapped in the output function. before being added as an url_rule. (right about here: https://github.com/python-restx/flask-restx/blob/master/flask_restx/api.py#L359) Since the output function is synchronous Flask 2.x won't detect the actual endpoint function is a coroutine. So that function will never be awaited and as a consequence not work.

Describe the solution you'd like It would be great if Flask Restx would integrate seamlessly with Flask 2.x. I suppose you can either make the output function async and this will probably just work under Flask 2.x but break under earlier versions or detect if your endpoint is a coroutine and add the correct output wrapper depending on that

Describe alternatives you've considered Currently I'm using the https://github.com/alex-sherman/unsync library as a workaround so I can keep my underlying async functions and use Flask Restx

JesseDeLoore avatar Aug 15 '21 06:08 JesseDeLoore

thanks for opening this request! This indeed would be a great addition bring restx up to parity with flask.

j5awry avatar Aug 16 '21 12:08 j5awry

Any updates here?

brennhill avatar Jan 21 '23 07:01 brennhill

flask 2.0 async compatibility would be a great enhancement.

felimuno avatar Apr 27 '23 17:04 felimuno

Could really use this!

brian-ketos avatar May 16 '23 11:05 brian-ketos

Would love this as well. Anyone figure out how unsync can get around this?

xevix avatar Aug 23 '23 01:08 xevix

👍 flask-restx is a great lib, async capabilities are the only thing missing in this

mshka avatar Nov 02 '23 18:11 mshka

even with flask > 3.0 and flask-restx 1.3 it still not working

engFelipeMonteiro avatar Jul 10 '24 14:07 engFelipeMonteiro