Browse Source

✏️ Fix typos in comment in `fastapi/applications.py` (#10045)

pull/10204/head
Ahsan Sheraz 2 years ago
committed by GitHub
parent
commit
9fc33f8565
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      fastapi/applications.py

24
fastapi/applications.py

@ -189,20 +189,20 @@ class FastAPI(Starlette):
# contextvars. # contextvars.
# This needs to happen after user middlewares because those create a # This needs to happen after user middlewares because those create a
# new contextvars context copy by using a new AnyIO task group. # new contextvars context copy by using a new AnyIO task group.
# The initial part of dependencies with yield is executed in the # The initial part of dependencies with 'yield' is executed in the
# FastAPI code, inside all the middlewares, but the teardown part # FastAPI code, inside all the middlewares. However, the teardown part
# (after yield) is executed in the AsyncExitStack in this middleware, # (after 'yield') is executed in the AsyncExitStack in this middleware.
# if the AsyncExitStack lived outside of the custom middlewares and # If the AsyncExitStack lived outside of the custom middlewares and
# contextvars were set in a dependency with yield in that internal # contextvars were set in a dependency with 'yield' in that internal
# contextvars context, the values would not be available in the # contextvars context, the values would not be available in the
# outside context of the AsyncExitStack. # outer context of the AsyncExitStack.
# By putting the middleware and the AsyncExitStack here, inside all # By placing the middleware and the AsyncExitStack here, inside all
# user middlewares, the code before and after yield in dependencies # user middlewares, the code before and after 'yield' in dependencies
# with yield is executed in the same contextvars context, so all values # with 'yield' is executed in the same contextvars context. Thus, all values
# set in contextvars before yield is still available after yield as # set in contextvars before 'yield' are still available after 'yield,' as
# would be expected. # expected.
# Additionally, by having this AsyncExitStack here, after the # Additionally, by having this AsyncExitStack here, after the
# ExceptionMiddleware, now dependencies can catch handled exceptions, # ExceptionMiddleware, dependencies can now catch handled exceptions,
# e.g. HTTPException, to customize the teardown code (e.g. DB session # e.g. HTTPException, to customize the teardown code (e.g. DB session
# rollback). # rollback).
Middleware(AsyncExitStackMiddleware), Middleware(AsyncExitStackMiddleware),

Loading…
Cancel
Save