Fastapi: [QUESTION] Possible bug in `routing` module L#49

Created on 5 Jul 2019  路  4Comments  路  Source: tiangolo/fastapi

Describe the bug
On this line field.validate() is passed a response: Response object, but the method signature for Field.validate() expects a Dict object - is this intentional?

I was investigating a bug very much similar to #361

To Reproduce
Steps to reproduce the behavior:
N/A

Expected behavior
The passed arguments should match with the parameter annotations.

Screenshots
N/A

Environment:

  • OS: e.g. Linux (in docker)
  • FastAPI Version : e.g. 0.31.0

    • Python version: 3.6.8

Additional context
Might be related to #361

bug confirmed good first issue

Most helpful comment

This was fixed by @patrickmckenna in #1031 :rocket: :tada:

All 4 comments

Field.validate function expects typing.Any in the latest version of pydantic: https://github.com/samuelcolvin/pydantic/blob/c3098a30cf87b6c17e154e85fe99dbe25a42d569/pydantic/fields.py#L417

It's funny -- if you look at the async def app function inside the get_app function, which is the only place serialize_response ever gets called, you'll notice it explicitly will not be called if the value of response is an instance of Response. So, actually Response is basically the only thing that shouldn't, under any circumstances, be provided to the function 馃槃.

So I'm pretty sure this is a mistake in the annotations -- response should probably be type hinted as typing.Any, and it might make more sense to rename the variable raw_response to prevent confusion.

Yep, good catch @wadkar , that's a bug.

Thanks @dmontagu for the analysis!

Maybe we could name it response_contents to make it more explicit.

I'll mark this issue as good-first-issue as the fix would be quite simple.

This was fixed by @patrickmckenna in #1031 :rocket: :tada:

Was this page helpful?
0 / 5 - 0 ratings