3.x Changelog

2.16.0

Released: 2025-05-04

Features

Logging: Selectively disable logging for status codes or exception types#

Add support for disabling stack traces for specific status codes or exception types when in debug mode or running with log_exceptions="always"

Disable tracebacks for ‘404 - Not Found’ exceptions
from litestar import Litestar
from litestar.logging import LoggingConfig

app = Litestar(
    route_handlers=[index, value_error, name_error],
    logging_config=LoggingConfig(
        disable_stack_trace={404},
        log_exceptions="always",
    ),
)

References: https://github.com/litestar-org/litestar/issues/4081, https://github.com/litestar-org/litestar/pull/4086

Reference route handler in error message for return value / status code mismatch#

Improve error message of ImproperlyConfiguredException raised when a route handler’s return value annotation is incompatible with its status code.

References: https://github.com/litestar-org/litestar/pull/4157

DTO: Improve inspection and tracebacks for generated functions#

Generated transfer functions now populate linecache to improve tracebacks and support introspection of the generated functions e.g. via inspect.getsource()

Before:

File "<string>", line 18, in func
TypeError: <something's wrong>

After:

File "dto_transfer_function_0971e01f653c", line 18, in func
TypeError: <something's wrong>

References: https://github.com/litestar-org/litestar/pull/4159

DTO: Add custom attribute accessor callable#

Add attribute_accessor property to AbstractDTO, that can be set to a custom getattr()-like function which will be used every time an attribute is accessed on a source instance

References: https://github.com/litestar-org/litestar/pull/4160

OpenAPI: Add custom example ids support#
OpenAPI: Allow passing scalar configuration options#

Add an options parameter to ScalarRenderPlugin, that can be used to pass options directly to scalar.

from litestar import Litestar
from litestar.openapi.config import OpenAPIConfig
from litestar.openapi.plugins import ScalarRenderPlugin

scalar_plugin = ScalarRenderPlugin(version="1.19.5", options={"showSidebar": False})

app = Litestar(
    route_handlers=[hello_world],
    openapi_config=OpenAPIConfig(
        title="Litestar Example",
        description="Example of Litestar with Scalar OpenAPI docs",
        version="0.0.1",
        render_plugins=[scalar_plugin],
        path="/docs",
    ),
)

References: https://github.com/litestar-org/litestar/issues/3951, https://github.com/litestar-org/litestar/pull/4162

Bugfixes

Typing: remove usage of private _AnnotatedAlias#

Remove deprecated usage of _AnnotatedAlias, which is no longer needed for backwards compatibility.

References: https://github.com/litestar-org/litestar/pull/4126

DI: Ensure generator dependencies always handle error during clean up#

Fix issue where dependency cleanup could be skipped during exception handling, if another exception happened during the cleanup itself.

  • Ensure all dependencies are cleaned up, even if exceptions occur.

  • Group exceptions using ExceptionGroup during cleanup phase.

References: https://github.com/litestar-org/litestar/pull/4148

CLI: Improve error message on ImportError#

Fix misleading error message when using --app CLI argument and an unrelated ImportError occurs. Unrelated import errors will now propagate as usual

References: https://github.com/litestar-org/litestar/issues/4129, https://github.com/litestar-org/litestar/pull/4152

CLI: Ensure dynamically added commands / groups are always visible#

Fix an issue where dynamically added commands or groups were not always visible during listing e.g. via --help

References: https://github.com/litestar-org/litestar/issues/2783, https://github.com/litestar-org/litestar/pull/4161

Testing: Ensure subprocess client does not swallow startup failure#

Ensure StartupError is raised by subprocess_sync_client() and subprocess_async_client() if the application failed to start within the timeout.

References: https://github.com/litestar-org/litestar/issues/4021, https://github.com/litestar-org/litestar/pull/4153

OpenAPI: Use prefixItems for fixed-length tuples#

Use prefixItems instead of array syntax to render fixed-length tuples

References: https://github.com/litestar-org/litestar/issues/4130, https://github.com/litestar-org/litestar/pull/4132

3.0.0

Released: 2024-08-30

Features

New stuff#breaking

This is a changelog entry

References: https://github.com/litestar-org/litestar/pull/1234