Skip to content

Commit 06efa69

Browse files
committed
v2.12.0
1 parent c487684 commit 06efa69

File tree

3 files changed

+180
-2
lines changed

3 files changed

+180
-2
lines changed

docs/release-notes/changelog.rst

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,184 @@
33
2.x Changelog
44
=============
55

6+
.. changelog:: 2.12.0
7+
:date: 2024-09-21
8+
9+
.. change:: Fix overzealous warning for greedy middleware ``exclude`` pattern
10+
:type: bugfix
11+
:pr: 3712
12+
13+
Fix a bug introduced in ``2.11.0`` (https://github.com/litestar-org/litestar/pull/3700),
14+
where the added warning for a greedy pattern use for the middleware ``exclude``
15+
parameter was itself greedy, and would warn for non-greedy patterns, e.g.
16+
``^/$``.
17+
18+
.. change:: Fix dangling coroutines in request extraction handling cleanup
19+
:type: bugfix
20+
:pr: 3735
21+
:issue: 3734
22+
23+
Fix a bug where, when a required header parameter was defined for a request that
24+
also expects a request body, failing to provide the header resulted in a
25+
:exc:`RuntimeWarning`.
26+
27+
.. code-block:: python
28+
29+
@post()
30+
async def handler(data: str, secret: Annotated[str, Parameter(header="x-secret")]) -> None:
31+
return None
32+
33+
If the ``x-secret`` header was not provided, warning like this would be seen:
34+
35+
.. code-block::
36+
37+
RuntimeWarning: coroutine 'json_extractor' was never awaited
38+
39+
40+
.. change:: OpenAPI: Correctly handle ``type`` keyword
41+
:type: bugfix
42+
:pr: 3715
43+
:issue: 3714
44+
45+
Fix a bug where a type alias created with the ``type`` keyword would create an
46+
empty OpenAPI schema entry for that parameter
47+
48+
.. change:: OpenAPI: Ensure valid schema keys
49+
:type: bugfix
50+
:pr: 3635
51+
:issue: 3630
52+
53+
Ensure that generated schema component keys are always valid according to
54+
`§ 4.8.7.1 <https://spec.openapis.org/oas/latest.html#fixed-fields-5>`_ of the
55+
OpenAPI specification.
56+
57+
58+
.. change:: OpenAPI: Correctly handle ``msgspec.Struct`` tagged unions
59+
:type: bugfix
60+
:pr: 3742
61+
:issue: 3659
62+
63+
Fix a bug where the OpenAPI schema would not include the struct fields
64+
implicitly generated by msgspec for its
65+
`tagged union <https://jcristharif.com/msgspec/structs.html#tagged-unions>`_
66+
support.
67+
68+
The tag field of the struct will now be added as a ``const`` of the appropriate
69+
type to the schema.
70+
71+
72+
.. change:: OpenAPI: Fix Pydantic 1 constrained string with default factory
73+
:type: bugfix
74+
:pr: 3721
75+
:issue: 3710
76+
77+
Fix a bug where using a Pydantic model with a ``default_factory`` set for a
78+
constrained string field would raise a :exc:`SerializationException`.
79+
80+
.. code-block:: python
81+
82+
class Model(BaseModel):
83+
field: str = Field(default_factory=str, max_length=600)
84+
85+
86+
.. change:: OpenAPI/DTO: Fix missing Pydantic 2 computed fields
87+
:type: bugfix
88+
:pr: 3721
89+
:issue: 3656
90+
91+
Fix a bug that would lead to Pydantic computed fields to be ignored during
92+
schema generation when the model was using a
93+
:class:`~litestar.contrib.pydantic.PydanticDTO`.
94+
95+
.. code-block:: python
96+
:caption: Only the ``foo`` field would be included in the schema
97+
98+
class MyModel(BaseModel):
99+
foo: int
100+
101+
@computed_field
102+
def bar(self) -> int:
103+
return 123
104+
105+
@get(path="/", return_dto=PydanticDTO[MyModel])
106+
async def test() -> MyModel:
107+
return MyModel.model_validate({"foo": 1})
108+
109+
.. change:: OpenAPI: Fix Pydantic ``json_schema_extra`` overrides only being merged partially
110+
:type: bugfix
111+
:pr: 3721
112+
:issue: 3656
113+
114+
Fix a bug where ``json_schema_extra`` were not reliably extracted from Pydantic
115+
models and included in the OpenAPI schema.
116+
117+
.. code-block:: python
118+
:caption: Only the title set directly on the field would be used for the schema
119+
120+
class Model(pydantic.BaseModel):
121+
with_title: str = pydantic.Field(title="new_title")
122+
with_extra_title: str = pydantic.Field(json_schema_extra={"title": "more_new_title"})
123+
124+
125+
@get("/example")
126+
async def example_route() -> Model:
127+
return Model(with_title="1", with_extra_title="2")
128+
129+
130+
.. change:: Support strings in ``media_type`` for ``ResponseSpec``
131+
:type: feature
132+
:pr: 3729
133+
:issue: 3728
134+
135+
Accept strings for the ``media_type`` parameter of :class:`~litestar.openapi.datastructures.ResponseSpec`,
136+
making it behave the same way as :paramref:`~litestar.response.Response.media_type`.
137+
138+
139+
.. change:: OpenAPI: Allow customizing schema component keys
140+
:type: feature
141+
:pr: 3738
142+
143+
Allow customizing the schema key used for a component in the OpenAPI schema.
144+
The supplied keys are enforced to be unique, and it is checked that they won't
145+
be reused across different types.
146+
147+
The keys can be set with the newly introduced ``schema_component_key`` parameter,
148+
which is available on :class:`~litestar.params.KwargDefinition`,
149+
:func:`~litestar.params.Body` and :func:`~litestar.params.Parameter`.
150+
151+
.. code-block:: python
152+
:caption: Two components will be generated: ``Data`` and ``not_data``
153+
154+
@dataclass
155+
class Data:
156+
pass
157+
158+
@post("/")
159+
def handler(
160+
data: Annotated[Data, Parameter(schema_component_key="not_data")],
161+
) -> Data:
162+
return Data()
163+
164+
@get("/")
165+
def handler_2() -> Annotated[Data, Parameter(schema_component_key="not_data")]:
166+
return Data()
167+
168+
.. change:: Raise exception when body parameter is annotated with non-bytes type
169+
:type: feature
170+
:pr: 3740
171+
172+
Add an informative error message to help avoid the common mistake of attempting
173+
to use the ``body`` parameter to receive validated / structured data by
174+
annotating it with a type such as ``list[str]``, instead of ``bytes``.
175+
176+
177+
.. change:: OpenAPI: Default to ``latest`` scalar version
178+
:type: feature
179+
:pr: 3747
180+
181+
Change the default version of the scalar OpenAPI renderer to ``latest``
182+
183+
6184
.. changelog:: 2.11.0
7185
:date: 2024-08-27
8186

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ maintainers = [
6060
name = "litestar"
6161
readme = "README.md"
6262
requires-python = ">=3.8,<4.0"
63-
version = "2.11.0"
63+
version = "2.12.0"
6464

6565
[project.urls]
6666
Blog = "https://blog.litestar.dev"

tools/prepare_release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def build_changelog_entry(release_info: ReleaseInfo, interactive: bool = False)
313313
for prs in release_info.pull_requests.values():
314314
for pr in prs:
315315
cc_type = pr.cc_type
316-
if cc_type in change_types or (interactive and click.confirm(f"Ignore PR #{pr.number} {pr.title!r}?")):
316+
if cc_type in change_types or (interactive and click.confirm(f"Include PR #{pr.number} {pr.title!r}?")):
317317
doc.add_change(pr)
318318
else:
319319
click.secho(f"Ignoring change with type {cc_type}", fg="yellow")

0 commit comments

Comments
 (0)