Ge0rg3 / flask-parameter-validation

Get and validate all Flask input parameters with ease.
https://pypi.org/project/Flask-Parameter-Validation/
28 stars 12 forks source link

Fix Async View Handling #41

Closed maxrimlinger closed 6 months ago

maxrimlinger commented 6 months ago

When adding async support for Flask-Parameter-Validation, the ValidateParameters decorator would always return an async coroutine, whether the Flask view function was async or not. This resulted in unexpected behavior when adding decorators that wrapped ValidateParameters as they may not have been expecting an async function that must be awaited.

To fix this, ValidateParameters now only returns an async coroutine to any decorators upstream if it recieved an async coroutine. Otherwise, it will return a function.

I've added a good few tests to make sure async and sync decorators are handled predictably across types and parameter types.

Ge0rg3 commented 6 months ago

Nice find @maxwrimlinger and many thanks for the thorough PR! Will get this merged and released asap 🙌

Ge0rg3 commented 6 months ago

Just deployed this as a hotfix, current version is 2.3.1, thanks again 💯