Maillol / aiohttp-pydantic

Aiohttp View that validates request body and query sting regarding the annotations declared in the View method
MIT License
67 stars 21 forks source link

Complex types in Groups #41

Closed Parapheen closed 2 years ago

Parapheen commented 2 years ago

I am trying to use Groups for multiple query parameters.

class Filters(Group):
    author: Optional[str]
    state: Optional[State]
    game: Optional[Game]
    talent: Optional[Talent]

But I am getting an error

    class View(PydanticView):
../../../opt/miniconda3/envs/fcast-backend/lib/python3.9/abc.py:106: in __new__
    cls = super().__new__(mcls, name, bases, namespace, **kwargs)
../../../opt/miniconda3/envs/fcast-backend/lib/python3.9/site-packages/aiohttp_pydantic/view.py:56: in __init_subclass__
    decorated_handler = inject_params(handler, cls.parse_func_signature)
../../../opt/miniconda3/envs/fcast-backend/lib/python3.9/site-packages/aiohttp_pydantic/view.py:118: in inject_params
    injectors = parse_func_signature(handler)
../../../opt/miniconda3/envs/fcast-backend/lib/python3.9/site-packages/aiohttp_pydantic/view.py:88: in parse_func_signature
    injectors.append(QueryGetter(qs_args, default_value(qs_args)))
../../../opt/miniconda3/envs/fcast-backend/lib/python3.9/site-packages/aiohttp_pydantic/injectors.py:113: in __init__
    self.model = type("QueryModel", (BaseModel,), attrs)
pydantic/main.py:198: in pydantic.main.ModelMetaclass.__new__
    ???
pydantic/fields.py:506: in pydantic.fields.ModelField.infer
    ???
pydantic/fields.py:436: in pydantic.fields.ModelField.__init__
    ???
pydantic/fields.py:557: in pydantic.fields.ModelField.prepare
    ???
pydantic/fields.py:831: in pydantic.fields.ModelField.populate_validators
    ???
pydantic/validators.py:765: in find_validators
    ???
E   RuntimeError: no validator found for <class 'app.schemas.vacancy.VacancyFilters'>, see `arbitrary_types_allowed` in Config

Is there a way to use complex types. In my case those types are Enums or it's supposed to work only with primitive types?

Parapheen commented 2 years ago

the problem was in how I describe Group in handler.

Should be just Filters, I was using Optional[Filters]