I have a pydantic model:
class CreateModelCommand(BaseModel):
name: Optional[str] = None
description: Optional[str] = None
And I want to send it along two UploadFiles:
@app.post("/")
async def create_model(
command: CreateModelCommand,
binary: UploadFile,
config: UploadFile,
):
model = model_service.create_model(command, binary, config)
But since command
is a pydantic model, FastApi tries to convert the entire body to a dict, as stated here: https://fastapi.tiangolo.com/tutorial/body-multiple-params/#multiple-body-parameters.
This returns a Unprocessable Entity
error, since it can't convert the files to dicts. Now I am asking if I can somehow disable this automatic detection or if I am simply using bad practise.