feat: add dependency_scope="lifespan" for application-lifetime depend…#13
Open
hbrooks wants to merge 12 commits into
Open
feat: add dependency_scope="lifespan" for application-lifetime depend…#13hbrooks wants to merge 12 commits into
hbrooks wants to merge 12 commits into
Conversation
- 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
…ons) 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
…ecycle scenario Made-with: Cursor
… remove unreachable collector branch Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mirror of fastapi/fastapi#15097 by @essentiaMarco