fix(app): pass Reflex app instance to lifespan task app parameter#6358
fix(app): pass Reflex app instance to lifespan task app parameter#6358BABTUNA wants to merge 3 commits intoreflex-dev:mainfrom
Conversation
Greptile SummaryThis PR fixes lifespan task parameter injection so that tasks declaring an Confidence Score: 5/5Safe to merge — the fix is correct and non-breaking; only remaining feedback is a P2 test coverage suggestion. The core logic change is a one-line substitution ( No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant SA as Starlette (ASGI)
participant LM as LifespanMixin._run_lifespan_tasks(starlette_app)
participant T as Lifespan Task
SA->>LM: call with starlette_app instance
LM->>LM: inspect.signature(task)
alt task has "app" param
LM->>LM: partial(task, app=self) — Reflex instance
end
alt task has "starlette_app" param
LM->>LM: partial(task, starlette_app=starlette_app) — Starlette instance
end
LM->>T: task()
T-->>LM: coroutine / context manager / plain return
Reviews (1): Last reviewed commit: "Pass Reflex app instance to lifespan tas..." | Re-trigger Greptile |
masenf
left a comment
There was a problem hiding this comment.
looks good. need a doc update in docs/utility_methods/lifespan_tasks.md
# Conflicts: # tests/units/app_mixins/test_lifespan.py
# Conflicts: # tests/units/app_mixins/test_lifespan.py
57d5e0c to
73913f5
Compare
|
@masenf changes up ! |
| class DummyApp(LifespanMixin): | ||
| """Minimal test app based on the lifespan mixin.""" | ||
|
|
||
| app = DummyApp() |
There was a problem hiding this comment.
can we just instantiate a LifespanMixin directly? no need to define this class in each test

All Submissions:
github.com/reflex-dev/reflex/blob/main/CONTRIBUTING.md) file?
Requests for the desired
changed?
Type of change
New Feature Submission:
Changes To Core Features:
like us to include them?
Description
This fixes lifespan task app injection so tasks that declare an
appparameter receive the Reflex app instance (
rx.App) instead of theStarlette wrapper.
Before:
_run_lifespan_tasks, tasks with anappparameter were called withthe Starlette lifespan app object.
appinconsistent with expected Reflex app behavior.After:
appparameter now receivesself(the Reflex app instance).starlette_appparameter support for tasks thatexplicitly want the Starlette instance.
Tests
Added regression test:
tests/units/app_mixins/test_lifespan.pytest_lifespan_task_app_param_receives_reflex_app_instanceValidation run:
uv run pytest tests/units/app_mixins/test_lifespan.py -quv run ruff check reflex/app_mixins/lifespan.py tests/units/app_mixins/ test_lifespan.pyCloses #6331