Skip to content

How to replace deprecated on_event by lifespan()? #3

Open
@stephane-rbn

Description

@stephane-rbn

@codesensei-courses Hi!

I'm currently at the point in the course where we're connecting to a SQLite database for the first time. You're using on_event() from SQLModel to add an event handler for the application on startup like so: https://github.com/codesensei-courses/fastapi_fundamentals/blob/c4de006900b495acdf4b973154027f24d790b370/carsharing.py#L32C1-L32C24

However, it is indicated as deprecated on FastAPI's documentation: https://fastapi.tiangolo.com/advanced/events/#alternative-events-deprecated

Still, I am not sure how to reproduce this behavior using lifespan() instead. Would you show us how you would do it in your code?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions