maximdanilchenko/aiohttp-apispec

Question about validation_middleware

korcky opened this issue · 4 comments

Currently code of this method looks like:

async def validation_middleware(request: web.Request, handler) -> web.Response:
    ...
    for schema in schemas:
        data = await request.app["_apispec_parser"].parse(
            schema["schema"], request, locations=schema["locations"]
        )
        if data:
            try:
                result.update(data)
            except (ValueError, TypeError):
                result = data
                break
    else:
        result.update(request.match_info)
    request[request.app["_apispec_request_data_name"]] = result
    return await handler(request)

So, if schema successfully parsed a request arguments (basically transform each argument to their relative type), they will be put in result, but eventually (if data a dictionary) arguments in result will be replaced by their string representation.

The question is Why? Why replacing a right type arguments with their string representation?

@korcky, you talk about usage of @request_schema with location="match_info", am I right?

@maximdanilchenko, yep, you're correct

Yes. You are right. It is an issue and it is my fault. It was designed like it in the very beginning of the project. And it was incorrect to change the behavior after some time. I will remove this else block in 2.0 version or we can add a new middleware without it. What do you think?

I'm not quite affected by this issue for now) So, I think it would better to fix in 2.0 version.