Skip to content

FastAPI 0.137.0 breaks optimade server because landing.router is a plain Starlette Router #2383

@DanielYang59

Description

@DanielYang59

after https://github.com/fastapi/fastapi/releases/tag/0.137.0

from optimade.server.main import main

breaks with:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    from optimade.server.main import main as optimade
  File "/Users/yang/test-venv/.venv/lib/python3.13/site-packages/optimade/server/main.py", line 10, in <module>
    app = create_app(ServerConfig())
  File "/Users/yang/test-venv/.venv/lib/python3.13/site-packages/optimade/server/create_app.py", line 298, in create_app
    app.include_router(endpoint.router)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/Users/yang/test-venv/.venv/lib/python3.13/site-packages/fastapi/applications.py", line 1553, in include_router
    self.router.include_router(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^
        router,
        ^^^^^^^
    ...<8 lines>...
        generate_unique_id_function=generate_unique_id_function,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/yang/test-venv/.venv/lib/python3.13/site-packages/fastapi/routing.py", line 2428, in include_router
    assert not router._contains_router(self), (
               ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Router' object has no attribute '_contains_router'

likely because:

Before this, router.include_router(other_router) would take each path operation from other_router and "clone" it, or recreate it from scratch.

from starlette.routing import Route, Router

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions