Skip to content

Upgrading starlette 0.15 to 0.16

Breaking0.15.0 → 0.16.0Breaking2Deprecated1Fixed2Other1

BreakingUpgrade verdict

2 breaking changes.

  • Code that called get_env on Jinja2Templates will no longer work.
  • Setting the async backend on the TestClient class no longer works; pass it when creating the client instead.
  • Lifespan handlers should be wrapped with contextlib.asynccontextmanager instead of passing a bare generator function.
3 items need code or config changes
Breaking2
Removes the starlette.templates.Jinja2Templates.get_env method.
starlette.templates.Jinja2Templates.get_env
Removes the ClassVar starlette.testclient.TestClient.async_backend; the backend is now set via constructor kwargs.
starlette.testclient.TestClient.async_backend
Deprecated1
Deprecates passing an Async Generator Function or Generator Function to starlette.router.Router(lifespan_context=).
starlette.router.Router(lifespan_context=)contextlib.asynccontextmanager

Generated by DepDelta from published Python source. Not mixed with prose notes.

  • changed: constructor Starlette(debug: bool=…, routes: typing.Sequence[BaseRoute]=…, middleware: typing.Sequence[Middleware]=…, exception_handlers: typing.Dict[typing.Union[int, typing.Type[Exception]], typing.Callable]=…, on_startup: typing.Sequence[typing.Callable]=…, on_shutdown: typing.Sequence[typing.Callable]=…, lifespan: typing.Callable[[Starlette], typing.AsyncGenerator]=…) -> None → constructor Starlette(debug: bool=…, routes: typing.Sequence[BaseRoute]=…, middleware: typing.Sequence[Middleware]=…, exception_handlers: typing.Dict[typing.Union[int, typing.Type[Exception]], typing.Callable]=…, on_startup: typing.Sequence[typing.Callable]=…, on_shutdown: typing.Sequence[typing.Callable]=…, lifespan: typing.Callable[[Starlette], typing.AsyncContextManager]=…) -> None
  • changed: constructor Router(routes: typing.Sequence[BaseRoute]=…, redirect_slashes: bool=…, default: ASGIApp=…, on_startup: typing.Sequence[typing.Callable]=…, on_shutdown: typing.Sequence[typing.Callable]=…, lifespan: typing.Callable[[typing.Any], typing.AsyncGenerator]=…) -> None → constructor Router(routes: typing.Sequence[BaseRoute]=…, redirect_slashes: bool=…, default: ASGIApp=…, on_startup: typing.Sequence[typing.Callable]=…, on_shutdown: typing.Sequence[typing.Callable]=…, lifespan: typing.Callable[[typing.Any], typing.AsyncContextManager]=…) -> None
  • removed: method Jinja2Templates.get_env(directory: str) -> jinja2.Environment
  • removed: field TestClient.async_backend: typing.Dict[str, typing.Any]
  • changed: constructor TestClient(app: typing.Union[ASGI2App, ASGI3App], base_url: str=…, raise_server_exceptions: bool=…, root_path: str=…) -> None → constructor TestClient(app: typing.Union[ASGI2App, ASGI3App], base_url: str=…, raise_server_exceptions: bool=…, root_path: str=…, backend: str=…, backend_options: typing.Optional[typing.Dict[str, typing.Any]]=…) -> None
  • changed: constructor WebSocketTestSession(app: ASGI3App, scope: Scope, async_backend: typing.Dict[str, typing.Any]) -> None → constructor WebSocketTestSession(app: ASGI3App, scope: Scope, portal_factory: _PortalFactoryType) -> None
  • added: field TestClient.portal: typing.Optional[anyio.abc.BlockingPortal]