vapor-ware / fastapi-rfc7807

RFC-7807 compliant problem detail error response handler for FastAPI applications
GNU General Public License v3.0
19 stars 7 forks source link

does not work with latest version fastapi (0.100.1) #21

Open arbakker opened 1 year ago

arbakker commented 1 year ago

When running the following example code:

from fastapi import FastAPI
from fastapi_rfc7807 import middleware
import uvicorn

app = FastAPI()
middleware.register(app)

@app.get('/error')
async def error():
    raise ValueError('something went wrong')

def main():
    uvicorn.run(
        "coordinates_transformation_api.main:app", workers=2, port=8080, host="0.0.0.0"
    )

if __name__ == "__main__":
    main()

With the following versions and Python v3.11.4:

fastapi==0.100.1
fastapi-rfc7807==0.5.0
uvicorn==0.23.2

With:

python main.py

The application fails with the following message:

ImportError: cannot import name 'get_model_definitions' from 'fastapi.openapi.utils' (/home/anton/.local/lib/python3.11/site-packages/fastapi/openapi/utils.py)

Error is caused by FastAPI that recently switched to Pydantic v2. See the commit here.

I created this issue mainly to document the issue, and to perhaps revisit later myself (considering the lack of activity in the project).

dineshbvadhia commented 1 year ago

@rem13 The https://github.com/rem13/fastapi-rfc7807/pull/1/commits/dd571060f0de6bbbcaba321f897c54c7f9715892 fix doesn't work because it is not solving for Pydantic V2. See the fastapi Pydantic V2 and V1 code in _compat.py at https://github.com/tiangolo/fastapi/blob/942ee69d857710ee4f0dffce50b6d4d4db10b540/fastapi/_compat.py#L46 and https://github.com/tiangolo/fastapi/blob/942ee69d857710ee4f0dffce50b6d4d4db10b540/fastapi/_compat.py#L260