An incomplete attempt at trying to allow pydantic.v1 models in FastAPI. My overall conclusion is this is probably a waste of time and too risky, likely adds more risk and takes more time than modifying all models to work with Pydantic v2. There are too many edge cases with FastAPI usage of the global fastapi._compat.PYDANTIC_V2
variable which gets resolved at import time.
FastAPI 0.115.5 and Pydantic 2.10.2
Invoke patch_v2_compat()
before you do anything with the FastAPI
application (like adding routes):