Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lifespan events are not called when using FastAPI versioning #77

Open
MathiasYde opened this issue Oct 24, 2024 · 1 comment
Open

Lifespan events are not called when using FastAPI versioning #77

MathiasYde opened this issue Oct 24, 2024 · 1 comment

Comments

@MathiasYde
Copy link

Describe the bug
When using VersionedFastAPI wrapper object, lifespan event is not called

To Reproduce
Run

from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi_versioning import VersionedFastAPI

@asynccontextmanager
async def lifespan(app: FastAPI):
    print("Starting app")
    yield
    print("Stopping app")

app = FastAPI(lifespan=lifespan)

# run uvicorn main:app with and without VersionedFastAPI
# app = VersionedFastAPI(app)

Expected behavior
The lifespan events should still be called using or not using VersionedFastAPI

@tslater2006
Copy link

We ran into this same problem so I wanted to just drop you a note, you can pass the lifespan=lifespan to the VersionedFastAPI(app) call and it should work. That constructor takes kwargs and passes them onto the base FastAPI app.

app = VersionedFastAPI(
    app,
    lifespan=lifespan
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants