Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using flask-pydantic with Python Dependency Injection Framework #49

Open
akhundMurad opened this issue Mar 30, 2022 · 7 comments
Open

Comments

@akhundMurad
Copy link

akhundMurad commented Mar 30, 2022

Hi! I am using this module with Python Dependency Injection Framework and when i try to use Provider in kwargs of the view i am getting:
RuntimeError: no validator found for <class '...'>, see arbitrary_types_allowed in Config
Reason of this error is the fact that @Validate decorator ignores only kwargs named as "query", "body", "return".
It would be better if @Validate decorator ignored kwargs which default is Provide instance

Sample code:

@bp.route('/api/posts', methods=['GET'])
@inject
@validate(response_many=True)
def get_posts(
        service: PostService = Provide[Container.services.post_service]
) -> List[ReadPost]:
    ...
@guywilsonjr
Copy link

So it's saying PostService has no methods with @validate. Can you show the PostService class?

@akhundMurad
Copy link
Author

İt is because of PostService class is not Pydantic model. PostService class is just simple object with crud

@davidhariri
Copy link

davidhariri commented Apr 6, 2022

I recently started getting this erorr RuntimeError: no validator found for <class 'models.client.Client'>, see arbitrary_types_allowed in Config as well. Did something in pydantic or flask_pydantic change? The following code used to work just fine:

from flask_pydantic import validate

@blueprint.route("/clone", subdomain="<subdomain>", methods=["POST"])
@inject_client()
@validate()
def clone_client_endpoint(
    body: ClientCloneReq, # A Pydantic model
    client: Client, # not a Pydantic model, comes from @inject_client()
    **kwargs
):

@akhundMurad
Copy link
Author

I think this issue not only about Python Dependency Injection Framework. This error appears when we use not Pydantic models in annotations

@davidhariri
Copy link

I think this issue not only about Python Dependency Injection Framework. This error appears when we use not Pydantic models in annotations

Yeah, just weird that this is broken now. Definitely worked before we upgraded from 0.4 to 0.9.

@piotrcybulski-profl
Copy link

I had the same issue and did a little investigation. The problem seems to be with validate_path_params method in validate decorator. That was introduced in 0.7.0 version, so it tell why David didn't have the issue with version 0.4.0. The issue is, it takes path parameters from the method arguments instead of route as it should.

@maldoinc
Copy link

Encountering the same issue. We use Wireup for DI and flask-pydantic as well. Sadly can't use both on the same view as flask-pydantic will throw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants