3.x Changelog¶
3.0.0¶
Released: 2024-08-30Features¶
- Remove all SQLAlchemy modules in favor of direct advanced-alchemy imports#breaking
Remove all SQLAlchemy functionality from Litestar. Both
litestar.contrib.sqlalchemyandlitestar.plugins.sqlalchemymodules have been completely removed. Users must now import directly fromadvanced_alchemy.extensions.litestar.Migration: -
from litestar.contrib.sqlalchemy import X→from advanced_alchemy.extensions.litestar import X-from litestar.plugins.sqlalchemy import Y→from advanced_alchemy.extensions.litestar import YThis completes the separation of concerns, with advanced-alchemy being the sole provider of SQLAlchemy integration for Litestar.
References: https://github.com/litestar-org/litestar/pull/TBD
- Remove deprecated
litestar.contrib.prometheusmodule#breaking Remove the deprecated
litestar.contrib.prometheusmodule. Code still using imports from this module should switch to usinglitestar.plugins.prometheus.References: https://github.com/litestar-org/litestar/issues/4305, https://github.com/litestar-org/litestar/pull/4328
- Make
AsyncTestClientasync-native#breaking Re-implement
AsyncTestClientto be async-native, i.e. use the currently running event loop to run the application, instead of running a separate event loop in a new thread. Additionally, a newAsyncWebSocketTestSessionhas been introduced, providing an async testing utility for WebSockets.To ensure consisten behaviour across
TestClientandAsyncTestClient, all testing utilities have been rewritten to be async first, with their synchronous counterparts proxying calls to the async implementation, which they run internally within a dedicated thread + event loop.References: https://github.com/litestar-org/litestar/issues/1920, https://github.com/litestar-org/litestar/pull/4291
- Remove deprecated plugin properties from
Litestar#breaking Remove deprecated
<plugin_type>_pluginsproperties fromLitestar.Removed
Use instead
Litestar.openapi_schema_pluginsLitestar.plugins.openapi_schemaLitestar.cli_pluginsLitestar.plugins.cliLitestar.serialization_pluginsLitestar.serialization.cliReferences: https://github.com/litestar-org/litestar/pull/4297
- Remove deprecated
allow_reservedandallow_empty_valueproperty fromResponseHeaderandOpenAPIHeader#breaking Remove the deprecated properties
allow_reservedandallow_empty_valuefromResponseHeaderandOpenAPIHeader.References: https://github.com/litestar-org/litestar/pull/4299
- Remove deprecated
traceback_line_limitparameter ofLoggingConfig#breaking The
traceback_line_limitparameter ofLoggingConfighas been removed. This parameter had no effect since version2.9.0, so it can be removed safely from applications without any change in behaviour.References: https://github.com/litestar-org/litestar/pull/4300
- Remove deprecated
litestar.middleware.corsmodule#breaking Remove the deprecated
litestar.middleware.corsmodule andlitestar.middleware.cors.CORSMiddleware. To configure the CORS middleware, useCORSConfig.References: https://github.com/litestar-org/litestar/pull/4309
- Remove deprecated
encoded_headersparameter from ASGI response classes andto_asgi_responsemethods#breaking The deprecated
encoded_headersparameter has been removed from the following clases:Existing code still using
encoded_headersshould be migrated to using theheadersparameter instead.References: https://github.com/litestar-org/litestar/pull/4311
- Remove deprecated
litestar.contrib.htmxmodule#breaking Remove the deprecated
litestar.contrib.htmxmodule. Code still using imports from this module should switch to usinglitestar_htmx.Install it via
litestar[htmx]extra.References: https://github.com/litestar-org/litestar/issues/4303, https://github.com/litestar-org/litestar/pull/4316
- Remove deprecated
LitestarType#breaking Remove the deprecated
litestar.types.internal_types.LitestarTypetype alias. In its stead,type[Litestar]can be used.References: https://github.com/litestar-org/litestar/pull/4312
- Remove deprecated
TemplateContext#breaking Remove the deprecated
litestar.template.base.TemplateContexttype. Its usages should be replaced withcollections.abc.Mapping.References: https://github.com/litestar-org/litestar/pull/4313
- Remove deprecated
ASGIResponse.encoded_headersproperty#breaking Remove the deprecated
ASGIResponse.encoded_headersproperty. Instead,encode_headers()should be used.References: https://github.com/litestar-org/litestar/pull/4314
- Remove deprecated
pydantic_get_unwrapped_annotation_and_type_hints#breaking Remove the deprecated
pydantic_get_unwrapped_annotation_and_type_hintsfunction.References: https://github.com/litestar-org/litestar/pull/4315
- Remove deprecated
litestar.contrib.attrsmodule#breaking Remove the deprecated
litestar.contrib.attrsmodule. Code still using imports from this module should switch to usinglitestar.plugins.attrs.References: https://github.com/litestar-org/litestar/issues/4302, https://github.com/litestar-org/litestar/pull/4322
- Remove deprecated
litestar.contrib.jwtmodule#breaking Remove the deprecated
litestar.contrib.jwtmodule. Code still using imports from this module should switch to usinglitestar.security.jwt.References: https://github.com/litestar-org/litestar/issues/4304, https://github.com/litestar-org/litestar/pull/4333
- Remove deprecated
litestar.contrib.repositorymodule#breaking Remove the deprecated
litestar.contrib.repositorymodule. Code still using imports from this module should switch to usinglitestar.repository.References: https://github.com/litestar-org/litestar/issues/4307, https://github.com/litestar-org/litestar/pull/4337
- Remove deprecated
litestar.contrib.pydanticmodule#breaking Remove the deprecated
litestar.contrib.pydanticmodule. Code still using imports from this module should switch to usinglitestar.plugins.pydantic.References: https://github.com/litestar-org/litestar/issues/4306, https://github.com/litestar-org/litestar/pull/4339
- Remove deprecated module
litestar/contrib/minijnja#breaking Remove the deprecated module
litestar.contrib.minijnja. This module was created with a typo in its name (minijnja instead of minijinja). Insteadlitestar.contrib.minijinjashould be used.References: https://github.com/litestar-org/litestar/issues/4357, https://github.com/litestar-org/litestar/pull/4357
- Add
round_tripparameter toPydanticPlugin# New
round_trip: boolparameter toPydanticPluginallows serializing types likepydanctic.Jsoncorrectly.References: https://github.com/litestar-org/litestar/issues/4349, https://github.com/litestar-org/litestar/pull/4350
- Remove deprecated
litestar.contrib.minijinja.minijinja_from_statefunction#breaking Remove the deprecated
litestar.contrib.minijinja.minijinja_from_statefunction. Instead use a callable that receives the minijinjaStateobject as first argument.References: https://github.com/litestar-org/litestar/issues/4356, https://github.com/litestar-org/litestar/pull/4355
- Remove deprecated
litestar.contrib.piccolomodule#breaking Use
litestar[piccolo]extra installation target andlitestar_piccoloplugin instead: https://github.com/litestar-org/litestar-piccoloReferences: https://github.com/litestar-org/litestar/issues/4364, https://github.com/litestar-org/litestar/pull/4363
- Zero cost excluded middlewares#breaking
Middlewares inheriting from
ASGIMiddlewarewill now have zero runtime cost when they are excluded e.g. via thescopeorexclude_opt_keyoptions.Previously, the base middleware was always being invoked for every request, evaluating the exclusion criteria, and then calling the user defined middleware functions. If a middleware had defined
scopes = (ScopeType.HTTP,), it would still be called for every request, regardless of the scope type. Only for requests with the typeHTTP, it would then call the user’s function.Note
This behaviour is still true for the legacy
AbstractMiddlewareWith zero cost exclusion, the exclusion is being evaluated statically. At app creation time, when route handlers are registered and their middleware stacks are being built, a middleware that is to be excluded will simply not be included in the stack.
Note
Even though this change is marked as breaking, no runtime behaviour difference is expected. Some test cases may break though if they relied on the fact that the middleware wrapper created by
ASGIMiddlewarewas always being calledReferences:
- Support for
typing.ReadOnlyin typed dict schemas# Support unwrapping
ReadOnlytype in schemas like:from typing import ReadOnly, TypedDict class User(TypedDict): id: ReadOnly[int]
typing_extensions.ReadOnlyshould be used for python versions <3.13.References: https://github.com/litestar-org/litestar/issues/4423, https://github.com/litestar-org/litestar/pull/4424
- Add
should_bypass_for_scopetoASGIMiddlewareto allow excluding middlewares dynamically# Add a new attribute
should_bypass_for_scope; A callable which takes in aScopeand returns a boolean to indicate whether to bypass the middleware for the current request.References: https://github.com/litestar-org/litestar/pull/4441
Bugfixes¶
- Change
OptionaltoNotRequiredfor pydantic fields withdefault_factory# Now, in the OpenAPI schema,
pydanticfields withdefault_factoryare displayed as non-null and not required. Previously, this fields was nullable and not required.References: https://github.com/litestar-org/litestar/issues/4294, https://github.com/litestar-org/litestar/pull/4347