What happened
backend/app/main.py uses the @app.on_event("startup") decorator (line 115), which was deprecated in FastAPI 0.93.0 in favour of the lifespan async context manager pattern. Running the server emits the following deprecation warning:
DeprecationWarning: on_event is deprecated, use lifespan event handlers instead.
This is a maintenance issue — the on_event API will be removed in a future FastAPI release, and the warning clutters server logs.
Steps to reproduce
- Install the backend dependencies.
- Start the server:
uvicorn app.main:app --reload --port 8000
- Observe the deprecation warning in the console output.
Expected behaviour
No deprecation warning. The startup logic (await init_db()) runs correctly when the application starts.
Actual behaviour
Relevant code — backend/app/main.py, lines 115–117:
@app.on_event("startup")
async def startup():
await init_db()
FastAPI emits a DeprecationWarning at import time because on_event is scheduled for removal.
Environment
| Field |
Value |
| OS |
Any |
| Python version |
3.10+ |
| FastAPI version |
0.93+ |
| PatchPilot version / commit |
main |
Logs
DeprecationWarning: on_event is deprecated, use lifespan event handlers instead.
Additional context
Fix — replace the decorator with a lifespan context manager and pass it to the FastAPI constructor:
from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app: FastAPI):
# Startup
await init_db()
yield
# Shutdown (add any cleanup here in the future)
app = FastAPI(title="PatchPilot API", version="0.1.0", lifespan=lifespan)
The @app.on_event("startup") block is then deleted entirely. No other code needs to change.
This also has the benefit of making shutdown cleanup trivial to add in the future (after the yield).
Reference: FastAPI lifespan events docs
Acceptance criteria:
What happened
backend/app/main.pyuses the@app.on_event("startup")decorator (line 115), which was deprecated in FastAPI 0.93.0 in favour of thelifespanasync context manager pattern. Running the server emits the following deprecation warning:This is a maintenance issue — the
on_eventAPI will be removed in a future FastAPI release, and the warning clutters server logs.Steps to reproduce
uvicorn app.main:app --reload --port 8000Expected behaviour
No deprecation warning. The startup logic (
await init_db()) runs correctly when the application starts.Actual behaviour
Relevant code —
backend/app/main.py, lines 115–117:FastAPI emits a
DeprecationWarningat import time becauseon_eventis scheduled for removal.Environment
mainLogs
Additional context
Fix — replace the decorator with a
lifespancontext manager and pass it to theFastAPIconstructor:The
@app.on_event("startup")block is then deleted entirely. No other code needs to change.This also has the benefit of making shutdown cleanup trivial to add in the future (after the
yield).Reference: FastAPI lifespan events docs
Acceptance criteria:
@app.on_event("startup")is removed.lifespanasync context manager handlesawait init_db()on startup.FastAPI(lifespan=lifespan)is used when constructingapp.