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

Allow configuration to ignore injection of certain path parameters.

Open tedo-benchling opened this issue 9 months ago • 0 comments

If flask-pydantic is used in conjunction with other frameworks that inject values into the routes arguments then validate must be the first decorator or else it will try to validate input for those other injected routes.

E.g. If you have a decorator @authenticated that injects a authentication_payload into routes

@validate
@authenticated
def my_route(body_param: MyModel, authentication_payload: AuthenticationPayload) -> MyResponse:
 ...

This works because the @authenticated has a chance to inject the authentication_payload value before @validate tries to find a value. However

@authenticated
@validate
def my_route(body_param: MyModel, authentication_payload: AuthenticationPayload) -> MyResponse:
 ...

Does not work because @validate tries to find a value for authentication_payload before @authenticated gets a chance.

It would be nice to be able to

do @validate(ignore_path_params=["authentication_payload"]) or set a global configuration FLASK_PYDANTIC_VALIDATION_IGNORE_PARAMS which is a list of path_params to ignore.

tedo-benchling avatar Mar 16 '25 17:03 tedo-benchling