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

Broken Compat with Pydantic latest #33

Closed miili closed 2 years ago

miili commented 2 years ago

The Group parameters are broken with the latest pydantic version.

from __future__ import annotations

import logging
from aiohttp import web
from aiohttp_pydantic import PydanticView
from aiohttp_pydantic.injectors import Group

logging.basicConfig(level=logging.DEBUG)

class Test(Group):
    name: str
    age: int = 123

class TestView(PydanticView):
    async def get(self, test: Test):
        return web.Response(text=test.name)

app = web.Application()
app.router.add_view("/test", TestView)
web.run_app(app)

Query to http://0.0.0.0:8080/test?name=foo returns

[{"loc": ["test"], "msg": "field required", "type": "value_error.missing", "in": "query string"}]
Maillol commented 2 years ago

The issue is not the latest pydantic version but the usage of from __future__ import annotations

Maillol commented 2 years ago

Fixed in release 1.12.1 Thanks

miili commented 2 years ago

Thank you!