Skip to content

feat: add dependency_scope="lifespan" for application-lifetime depend…#13

Open
hbrooks wants to merge 12 commits into
masterfrom
demo/pr-15097
Open

feat: add dependency_scope="lifespan" for application-lifetime depend…#13
hbrooks wants to merge 12 commits into
masterfrom
demo/pr-15097

Conversation

@hbrooks
Copy link
Copy Markdown

@hbrooks hbrooks commented May 28, 2026

essentiaMarco and others added 12 commits March 13, 2026 23:39
- Fix _collect_lifespan_dependants: handle route-level flat.computed_scope
  and iterate flat.dependencies (was incorrectly iterating flat)
- No pragmas on noop_receive/noop_send; covered by test that uses
  Request.receive/send in a lifespan dependency
- Add test_collect_lifespan_dependants_route_level_scope for route-level
  lifespan branch
- Add test_lifespan_dependency_synthetic_request_receive_send for
  noop_receive/noop_send coverage
- Add test_lifespan_dependency_nested for dependency_cache hit (utils)
- Add test_lifespan_dependency_cannot_depend_on_request_scope and
  test_lifespan_dependency_not_initialized_raises for edge cases

Made-with: Cursor
- Wire lifespan-scoped deps in applications.py via _wrap_lifespan_with_dependency_cache
- Extend Depends(..., scope=...) with 'lifespan' in params/models/utils
- Resolved with merge of origin/master

Made-with: Cursor
- Default lifespan: use app.router for _DefaultLifespan (router has
  _startup/_shutdown; FastAPI app does not).
- Wrapper: when app is FastAPI, set fastapi_app from app and pass
  app.router to _run_lifespan_dependencies so lifespan deps are collected.
- Test: use only Request.receive() (Starlette Request has no .send).

Made-with: Cursor
…nts tests pass

- In FastAPI.__init__, when lifespan is an async or sync generator function,
  convert to context manager (asynccontextmanager / _wrap_gen_lifespan_context)
  before _wrap_lifespan_with_dependency_cache so orig_cm has __aenter__/__aexit__.

Made-with: Cursor
…rd] so pre-commit passes in CI

Made-with: Cursor
…r gen lifespans, sync dep, cache hit, unreachable test lines)

Made-with: Cursor
… remove unreachable collector branch

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants