Fastapi: [BUG] Broken against latest release of Starlette

Created on 5 Nov 2019  Â·  6Comments  Â·  Source: tiangolo/fastapi

Describe the bug
The latest release of Starlette 0.12.13 introduced a breaking change to the way it initialises the core Starlette class which is incompatible with FastAPI's use (lack of use of super()). Introduced by this change: https://github.com/encode/starlette/commit/91eefb2af3940364b051138bed47319e189d31be

To Reproduce
Steps to reproduce the behavior:

  1. Install Starlette 0.12.13 and FastAPI
  2. Attempt to start a FastAPI server

Expected behavior
Fast API server starts

Screenshots
If applicable, add screenshots to help explain your problem.

Environment:

  • OS: Linux

    • FastAPI version: 0.42.0, but problem exists in master

    • Python version: 3.8.0

bug

Most helpful comment

Now in fastapi pinned the 0.12.9 version. I think it isn't bug (at least in current release).

All 6 comments

Now in fastapi pinned the 0.12.9 version. I think it isn't bug (at least in current release).

The latest release of Starlette 0.12.13

I think the breakage is happening on v0.13, not v0.12.13. Here's the traceback I've got on Starlette v0.13 / FastAPI v0.42:

# app.py
from fastapi import FastAPI

app = FastAPI()
$ python app.py 
email-validator not installed, email fields will be treated as str.
To install, run: pip install email-validator
Traceback (most recent call last):
  File "app.py", line 3, in <module>
    app = FastAPI()
  File "/Users/florimond/Developer/datadog-projects/ddtrace-asgi/venv/lib/python3.8/site-packages/fastapi/applications.py", line 78, in __init__
    self.setup()
  File "/Users/florimond/Developer/datadog-projects/ddtrace-asgi/venv/lib/python3.8/site-packages/fastapi/applications.py", line 130, in setup
    self.add_exception_handler(HTTPException, http_exception_handler)
  File "/Users/florimond/Developer/datadog-projects/ddtrace-asgi/venv/lib/python3.8/site-packages/starlette/applications.py", line 124, in add_exception_handler
    self.exception_handlers[exc_class_or_status_code] = handler
AttributeError: 'FastAPI' object has no attribute 'exception_handlers'

But I agree with @prostomarkeloff — FastAPI v0.42 seems to be pinned to Starlette v0.12.9, so I'm not getting this error unless I forcefully install Starlette v0.13.

Thanks @prostomarkeloff and @florimondmanca for the help! :bowing_man: :clap:

Yeah @Chippiewill , that would be a feature request to update FastAPI to support the latest Starlette (that I will) rather than a bug.

Starlette 0.12.12 is safe to use with FastAPI, this bug only occurs under 0.12.13 and latter.

Now that FastAPI supports the latest Starlette (since version 0.50.0), may we close this issue @Chippiewill ?

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.

Was this page helpful?
0 / 5 - 0 ratings