Skip to content

response processing pipeline has too much magic #476

@toppk

Description

@toppk

test-fastapijson.py.txt

using the latest version from git, I notice some automagic in how response are modified that make it difficult to impact json encoding.

Here are my complaints:

  1. it seems to control json encoding, you must call JSONResponse (or private implementation) yourself. using response_class won't work because the data has already been modified

  2. types that cannot encode to json will be done itself. an object is something that shouldn't be able to encode to json without help, but somewhere there is some code that does it automatically.

The documentation talks about returning response directly or returning the data. It seems that there's more happening behind the scenes then is discussed.

My expectation is that if I return something that isn't json encodable, then I get that exception. For other reasons I'm not able to use response_model at the moment. I wonder if I were to use that, I'd have the ability to plug in the type->json converter there.

The sample code shows three functions, which show the behavior i'm exploring. I'm happy to explain further.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions