FastAPI's Swagger fails to load API definition

betterthanever2
PRO

10 months ago

Today, after deploying new version of an FastAPI application, I can see that Swagger (`/docs`) is not working, returning 500 error. I tried reverting the app to a previous version, but that didn't help at all, which makes me believe it's something on Railway rather then with my code.

App in question can be found at https://b.subjective.agency (this would redirect to /docs, which is a custom-set behavior, but then the Swagger would fail.).

In addition, here's the trace of that 500:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/opentelemetry/trace/__init__.py", line 589, in use_span
    yield span
  File "/usr/local/lib/python3.12/site-packages/opentelemetry/instrumentation/asgi/__init__.py", line 743, in __call__
    await self.app(scope, otel_receive, otel_send)
  File "/usr/local/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/usr/local/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/usr/local/lib/python3.12/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in __call__
    raise e
  File "/usr/local/lib/python3.12/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in __call__
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.12/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/usr/local/lib/python3.12/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/usr/local/lib/python3.12/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/fastapi/applications.py", line 247, in openapi
    return JSONResponse(self.openapi())
                        ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/fastapi/applications.py", line 219, in openapi
    self.openapi_schema = get_openapi(
                          ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/fastapi/openapi/utils.py", line 483, in get_openapi
    result = get_openapi_path(
             ^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/fastapi/openapi/utils.py", line 251, in get_openapi_path
    operation_parameters = get_openapi_operation_parameters(
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/fastapi/openapi/utils.py", line 106, in get_openapi_operation_parameters
    param_schema = get_schema_from_model_field(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/fastapi/_compat.py", line 202, in get_schema_from_model_field
    ] = field.field_info.title or field.alias.title().replace("_", " ")
                                  ^^^^^^^^^^^^^^^^^
AttributeError: 'Depends' object has no attribute 'title'

Depends is a special object in FastAPI used for injecting dependencies. I updated FastAPI to most recent version, but that changed nothing.

Solved

2 Replies

betterthanever2
PRO

10 months ago

As this may or may not be related:

Currently, I can't build an app at all: it tries to take a snapshot of the code and fails with Unexpected EOF. Not sure what's going on here.


10 months ago

We have shipped a fix for this issue, and you should no longer experience this error. Please let us know whether you're continuing to see issues.


Status changed to Awaiting User Response Railway 10 months ago


Railway
BOT

2 months ago

This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!

Status changed to Solved Railway about 2 months ago