Browse Source

Ignore cases when `v1.BaseModel` is passed when `BaseModel` (v2) is expected

pull/14582/head
johnslavik 7 months ago
parent
commit
83d55e4f08
Failed to extract signature
  1. 4
      fastapi/routing.py

4
fastapi/routing.py

@ -154,7 +154,7 @@ def _prepare_response_content(
exclude_none: bool = False,
) -> Any:
if isinstance(res, (may_v1.BaseModel, BaseModel)):
read_with_orm_mode = getattr(_get_model_config(res), "read_with_orm_mode", None)
read_with_orm_mode = getattr(_get_model_config(res), "read_with_orm_mode", None) # type: ignore[arg-type]
if read_with_orm_mode:
# Let from_orm extract the data from this model instead of converting
# it now to a dict.
@ -162,7 +162,7 @@ def _prepare_response_content(
# access instead of dict iteration, e.g. lazy relationships.
return res
return _model_dump(
res,
res, # type: ignore[arg-type]
by_alias=True,
exclude_unset=exclude_unset,
exclude_defaults=exclude_defaults,

Loading…
Cancel
Save