Skip to content

Commit

Permalink
v2.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
provinzkraut committed Sep 21, 2024
1 parent c487684 commit 06efa69
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 2 deletions.
178 changes: 178 additions & 0 deletions docs/release-notes/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,184 @@
2.x Changelog
=============

.. changelog:: 2.12.0
:date: 2024-09-21

.. change:: Fix overzealous warning for greedy middleware ``exclude`` pattern
:type: bugfix
:pr: 3712

Fix a bug introduced in ``2.11.0`` (https://github.com/litestar-org/litestar/pull/3700),
where the added warning for a greedy pattern use for the middleware ``exclude``
parameter was itself greedy, and would warn for non-greedy patterns, e.g.
``^/$``.

.. change:: Fix dangling coroutines in request extraction handling cleanup
:type: bugfix
:pr: 3735
:issue: 3734

Fix a bug where, when a required header parameter was defined for a request that
also expects a request body, failing to provide the header resulted in a
:exc:`RuntimeWarning`.

.. code-block:: python
@post()
async def handler(data: str, secret: Annotated[str, Parameter(header="x-secret")]) -> None:
return None
If the ``x-secret`` header was not provided, warning like this would be seen:

.. code-block::
RuntimeWarning: coroutine 'json_extractor' was never awaited
.. change:: OpenAPI: Correctly handle ``type`` keyword
:type: bugfix
:pr: 3715
:issue: 3714

Fix a bug where a type alias created with the ``type`` keyword would create an
empty OpenAPI schema entry for that parameter

.. change:: OpenAPI: Ensure valid schema keys
:type: bugfix
:pr: 3635
:issue: 3630

Ensure that generated schema component keys are always valid according to
`§ 4.8.7.1 <https://spec.openapis.org/oas/latest.html#fixed-fields-5>`_ of the
OpenAPI specification.


.. change:: OpenAPI: Correctly handle ``msgspec.Struct`` tagged unions
:type: bugfix
:pr: 3742
:issue: 3659

Fix a bug where the OpenAPI schema would not include the struct fields
implicitly generated by msgspec for its
`tagged union <https://jcristharif.com/msgspec/structs.html#tagged-unions>`_
support.

The tag field of the struct will now be added as a ``const`` of the appropriate
type to the schema.


.. change:: OpenAPI: Fix Pydantic 1 constrained string with default factory
:type: bugfix
:pr: 3721
:issue: 3710

Fix a bug where using a Pydantic model with a ``default_factory`` set for a
constrained string field would raise a :exc:`SerializationException`.

.. code-block:: python
class Model(BaseModel):
field: str = Field(default_factory=str, max_length=600)
.. change:: OpenAPI/DTO: Fix missing Pydantic 2 computed fields
:type: bugfix
:pr: 3721
:issue: 3656

Fix a bug that would lead to Pydantic computed fields to be ignored during
schema generation when the model was using a
:class:`~litestar.contrib.pydantic.PydanticDTO`.

.. code-block:: python
:caption: Only the ``foo`` field would be included in the schema
class MyModel(BaseModel):
foo: int
@computed_field
def bar(self) -> int:
return 123
@get(path="/", return_dto=PydanticDTO[MyModel])
async def test() -> MyModel:
return MyModel.model_validate({"foo": 1})
.. change:: OpenAPI: Fix Pydantic ``json_schema_extra`` overrides only being merged partially
:type: bugfix
:pr: 3721
:issue: 3656

Fix a bug where ``json_schema_extra`` were not reliably extracted from Pydantic
models and included in the OpenAPI schema.

.. code-block:: python
:caption: Only the title set directly on the field would be used for the schema
class Model(pydantic.BaseModel):
with_title: str = pydantic.Field(title="new_title")
with_extra_title: str = pydantic.Field(json_schema_extra={"title": "more_new_title"})
@get("/example")
async def example_route() -> Model:
return Model(with_title="1", with_extra_title="2")
.. change:: Support strings in ``media_type`` for ``ResponseSpec``
:type: feature
:pr: 3729
:issue: 3728
Accept strings for the ``media_type`` parameter of :class:`~litestar.openapi.datastructures.ResponseSpec`,
making it behave the same way as :paramref:`~litestar.response.Response.media_type`.
.. change:: OpenAPI: Allow customizing schema component keys
:type: feature
:pr: 3738
Allow customizing the schema key used for a component in the OpenAPI schema.
The supplied keys are enforced to be unique, and it is checked that they won't
be reused across different types.
The keys can be set with the newly introduced ``schema_component_key`` parameter,
which is available on :class:`~litestar.params.KwargDefinition`,
:func:`~litestar.params.Body` and :func:`~litestar.params.Parameter`.
.. code-block:: python
:caption: Two components will be generated: ``Data`` and ``not_data``
@dataclass
class Data:
pass
@post("/")
def handler(
data: Annotated[Data, Parameter(schema_component_key="not_data")],
) -> Data:
return Data()
@get("/")
def handler_2() -> Annotated[Data, Parameter(schema_component_key="not_data")]:
return Data()
.. change:: Raise exception when body parameter is annotated with non-bytes type
:type: feature
:pr: 3740
Add an informative error message to help avoid the common mistake of attempting
to use the ``body`` parameter to receive validated / structured data by
annotating it with a type such as ``list[str]``, instead of ``bytes``.
.. change:: OpenAPI: Default to ``latest`` scalar version
:type: feature
:pr: 3747
Change the default version of the scalar OpenAPI renderer to ``latest``
.. changelog:: 2.11.0
:date: 2024-08-27
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ maintainers = [
name = "litestar"
readme = "README.md"
requires-python = ">=3.8,<4.0"
version = "2.11.0"
version = "2.12.0"

[project.urls]
Blog = "https://blog.litestar.dev"
Expand Down
2 changes: 1 addition & 1 deletion tools/prepare_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def build_changelog_entry(release_info: ReleaseInfo, interactive: bool = False)
for prs in release_info.pull_requests.values():
for pr in prs:
cc_type = pr.cc_type
if cc_type in change_types or (interactive and click.confirm(f"Ignore PR #{pr.number} {pr.title!r}?")):
if cc_type in change_types or (interactive and click.confirm(f"Include PR #{pr.number} {pr.title!r}?")):
doc.add_change(pr)
else:
click.secho(f"Ignoring change with type {cc_type}", fg="yellow")
Expand Down

0 comments on commit 06efa69

Please sign in to comment.