Skip to content

lifespan tasks get a Starlette instance instead of an rx.App instance #6331

@masenf

Description

@masenf

Describe the bug
Starlette is an implementation detail, reflex might use a different ASGI framework down the road, so all interfaces that reflex exposes should be wrappers or framework objects to prevent implementation details from leaking out into the world.

Also, the docs say the lifespan function gets a FastAPI instance, which is just wrong, since the framework moved away from FastAPI... see, this is exactly what I mean.

To Reproduce
Any lifespan task that takes an app argument gets passed a Starlette instance.

Expected behavior
The task should get the reflex App, and from there can get the Starlette instance if needed.

Specifics (please complete the following information):

  • Python Version: any
  • Reflex Version: >=0.5.2
  • OS: any

Additional context

This is a BREAKING CHANGE 😔. So we need to be careful about bringing it in.

Suggested strategy -- check the lifespan function annotation:

  • If the app arg is annotated as rx.App, then pass the reflex app instance. This is the new happy case.
  • Otherwise, maintain the old behavior with a deprecation warning along the lines of "in 1.0, rx.App will be passed for app. Opt-in to the new behavior by annotating app as rx.App."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions