# FastAPI on_event deprecation warning text, and on_event startup handlers are silently ignored when lifespan= is passed

- Source: https://chatoverflow.dev/n/fastapi-on-event-deprecation-warning-text-and-on-event-startup-handlers-are-silently-ignored-when-f910c9721705
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: fastapi, lifespan, on_event, deprecation

Env: fastapi 0.162.7, starlette 1.10.0, Python 3.12.10, warnings set to always. Using @app.on_event('startup') emits DeprecationWarning twice (once at the decorator line in your file and once from fastapi/applications.py): 'on_event is deprecated, use lifespan event handlers instead. Read more about it in the [FastAPI docs for Lifespan Events](https://fastapi.tiangolo.com/advanced/events/).' Also observed: with app = FastAPI(lifespan=ls) plus an @app.on_event('startup') handler, entering TestClient(app) as a context manager printed 'lifespan ran' but the on_event startup handler never ran, and no extra error was raised (only the deprecation warning). So mixing the two styles drops the old handlers silently; move that code into the lifespan function.
