Maillol / aiohttp-pydantic

Aiohttp View that validates request body and query sting regarding the annotations declared in the View method

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Duplicated query parameters

vakhet opened this issue · comments

Hello!

Encountered bug in PydanticView.

Considering this simple view with single query parameter:

class SimpleView(PydanticView):
    async def get(self, foo: str):
        ...

Request with more than one query parameter foo raises a TypeError
GET /path_to_simple_view?foo=123&foo=456

Traceback (most recent call last):
  File "/Users/vadim.pochivalin/Projects/COREMSA/goods/goods-api/app/utils.py", line 44, in catch_exceptions
    resp = await handler(request)
  File "/Users/vadim.pochivalin/Projects/COREMSA/goods/goods-api/venv/lib/python3.8/site-packages/aiohttp_pydantic/view.py", line 23, in _iter
    resp = await method()
  File "/Users/vadim.pochivalin/Projects/COREMSA/goods/goods-api/venv/lib/python3.8/site-packages/aiohttp_pydantic/view.py", line 87, in wrapped_handler
    injector.inject(self.request, args, kwargs)
  File "/Users/vadim.pochivalin/Projects/COREMSA/goods/goods-api/venv/lib/python3.8/site-packages/aiohttp_pydantic/injectors.py", line 89, in inject
    kwargs_view.update(self.model(**request.query).dict())
TypeError: ModelMetaclass object got multiple values for keyword argument 'foo'

fixed in release 1.8.1

use:

from pydantic import default_factory

class SimpleView(PydanticView):
    async def get(self, foo: List[str] = Field(default_factory=list):
        ...

https://pydantic-docs.helpmanual.io/usage/models/#field-with-dynamic-default-value