Skip to content

Commit 0bd5feb

Browse files
committed
v2.3.0
Signed-off-by: Janek Nouvertné <25355197+provinzkraut@users.noreply.github.com>
1 parent 290c7a4 commit 0bd5feb

File tree

3 files changed

+556
-270
lines changed

3 files changed

+556
-270
lines changed

docs/release-notes/changelog.rst

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

6+
.. changelog:: 2.3.0
7+
:date: 2023/11/02
8+
9+
.. change:: Python 3.12 support
10+
:type: feature
11+
:pr: 2396
12+
:issue: 1862
13+
14+
Python 3.12 is now fully supported and tested.
15+
16+
.. change:: New layered parameter ``signature_types``
17+
:type: feature
18+
:pr: 2422
19+
20+
Types in this collection are added to ``signature_namespace`` using the type's
21+
``__name__`` attribute.
22+
This provides a nicer interface when adding names to the signature namespace
23+
w ithout modifying the type name, e.g.: ``signature_namespace={"Model": Model}``
24+
is equivalent to ``signature_types=[Model]``.
25+
26+
The implementation makes it an error to supply a type in ``signature_types``
27+
that has a value for ``__name__`` already in the signature namespace.
28+
29+
It will also throw an error if an item in ``signature_types`` has no
30+
``__name__`` attribute.
31+
32+
.. change:: Added RapiDoc for OpenAPI schema visualisation
33+
:type: feature
34+
:pr: 2522
35+
36+
Add support for using `RapiDoc <https://github.com/rapi-doc/RapiDoc>`_ for
37+
OpenAPI schema visualisation.
38+
39+
.. change:: Support Pydantic 1 & 2 within the same application
40+
:type: feature
41+
:pr: 2487
42+
43+
Added support for Pydantic 1 & 2 within the same application by integrating with
44+
Pydantic's backwards compatibility layer:
45+
46+
.. code-block:: python
47+
48+
from litestar import get
49+
from pydantic.v1 import BaseModel as BaseModelV1
50+
from pydantic import BaseModel
51+
52+
53+
class V1Foo(BaseModelV1):
54+
bar: str
55+
56+
57+
class V2Foo(BaseModel):
58+
bar: str
59+
60+
61+
@get("/1")
62+
def foo_v1(data: V1Foo) -> V1Foo:
63+
return data
64+
65+
66+
@get("/2")
67+
def foo_v2(data: V2Foo) -> V2Foo:
68+
return data
69+
70+
.. change:: Add ``ResponseCacheConfig.cache_response_filter`` to allow filtering responses eligible for caching
71+
:type: feature
72+
:pr: 2537
73+
:issue: 2501
74+
75+
``ResponseCacheConfig.cache_response_filter`` is predicate called by the
76+
response cache middleware that discriminates whether a response should be
77+
cached, or not.
78+
79+
80+
.. change:: SSL support and self-signed certificates for CLI
81+
:type: feature
82+
:pr: 2554
83+
:issue: 2335
84+
85+
Add support for SSL and generating self-signed certificates to the CLI.
86+
87+
For this, three new arguments were added to the CLI's ``run`` command:
88+
89+
- ``--ssl-certfile``
90+
- ``--ssl-keyfile``
91+
- ``--create-self-signed-cert``
92+
93+
The ``--ssl-certfile`` and `--ssl-keyfile` flags are passed to uvicorn when
94+
using ``litestar run``. Uvicorn requires both to be passed (or neither) but
95+
additional validation was added to generate a more user friendly CLI errors.
96+
97+
The other SSL-related flags (like password or CA) were not added (yet). See
98+
`uvicorn CLI docs <https://www.uvicorn.org/#command-line-options>`_
99+
100+
**Generating of a self-signed certificate**
101+
102+
One more CLI flag was added (``--create-devcert``) that uses the
103+
``cryptography`` module to generate a self-signed development certificate. Both
104+
of the previous flags must be passed when using this flag. Then the following
105+
logic is used:
106+
107+
- If both files already exists, they are used and nothing is generated
108+
- If neither file exists, the dev cert and key are generated
109+
- If only one file exists, it is ambiguous what to do so an exception is raised
110+
111+
.. change:: Use custom request class when given during exception handling
112+
:type: bugfix
113+
:pr: 2444
114+
:issue: 2399
115+
116+
When a custom ``request_class`` is provided, it will now be used while returning
117+
an error response
118+
119+
.. change:: Fix missing OpenAPI schema for generic response type annotations
120+
:type: bugfix
121+
:pr: 2463
122+
:issue: 2383
123+
124+
OpenAPI schemas are now correctly generated when a response type annotation
125+
contains a generic type such as
126+
127+
.. code-block:: python
128+
129+
from msgspec import Struct
130+
from litestar import Litestar, get, Response
131+
from typing import TypeVar, Generic, Optional
132+
133+
T = TypeVar("T")
134+
135+
136+
class ResponseStruct(Struct, Generic[T]):
137+
code: int
138+
data: Optional[T]
139+
140+
141+
@get("/")
142+
def test_handler() -> Response[ResponseStruct[str]]:
143+
return Response(
144+
ResponseStruct(code=200, data="Hello World"),
145+
)
146+
147+
.. change:: Fix rendering of OpenAPI examples
148+
:type: bugfix
149+
:pr: 2509
150+
:issue: 2494
151+
152+
An issue was fixed where OpenAPI examples would be rendered as
153+
154+
.. code-block:: json
155+
156+
{
157+
"parameters": [
158+
{
159+
"schema": {
160+
"type": "string",
161+
"examples": [
162+
{
163+
"summary": "example summary",
164+
"value": "example value"
165+
}
166+
]
167+
}
168+
}
169+
]
170+
}
171+
172+
instead of
173+
174+
.. code-block:: json
175+
176+
{
177+
"parameters": [
178+
{
179+
"schema": {
180+
"type": "string"
181+
},
182+
"examples": {
183+
"example1": {
184+
"summary": "example summary"
185+
"value": "example value"
186+
}
187+
}
188+
}
189+
]
190+
}
191+
192+
.. change:: Fix non UTF-8 handling when logging requests
193+
:type: bugfix
194+
:issue: 2529
195+
:pr: 2530
196+
197+
When structlog is not installed, the request body would not get parsed and shown
198+
as a byte sequence. Instead, it was serialized into a string with the assumption
199+
that it is valid UTF-8. This was fixed by decoding the bytes with
200+
``backslashreplace`` before displaying them.
201+
202+
.. change:: Fix ``ExceptionHandler`` typing to properly support ``Exception`` subclasses
203+
:type: bugfix
204+
:issue: 2520
205+
:pr: 2533
206+
207+
Fix the typing for ``ExceptionHandler`` to support subclasses of ``Exception``,
208+
such that code like this will type check properly:
209+
210+
.. code-block:: python
211+
212+
from litestar import Litestar, Request, Response
213+
214+
215+
class CustomException(Exception):
216+
...
217+
218+
219+
def handle_exc(req: Request, exc: CustomException) -> Response:
220+
...
221+
222+
.. change:: Fix OpenAPI schema generation for variable length tuples
223+
:type: bugfix
224+
:issue: 2460
225+
:pr: 2552
226+
227+
Fix a bug where an annotation such as ``tuple[str, ...]`` would cause a
228+
``TypeError: '<' not supported between instances of 'NoneType' and 'OpenAPIType')``.
229+
230+
.. change:: Fix channels performance issue when polling with no subscribers in ``arbitrary_channels_allowed`` mode
231+
:type: bugfix
232+
:pr: 2547
233+
234+
Fix a bug that would cause high CPU loads while idling when using a
235+
``ChannelsPlugin`` with the ``arbitrary_channels_allowed`` enabled and while no
236+
subscriptions for any channel were active.
237+
238+
.. change:: Fix CLI schema export for non-serializable types when using ``create_examples=True``
239+
:type: bugfix
240+
:pr: 2581
241+
:issue: 2575
242+
243+
When trying to export a schema via the
244+
``litestar schema openapi --output schema.json`` making use of a non-JSON
245+
serializable type, would result in an encoding error because the standard
246+
library JSON serializer was used. This has been fixed by using Litestar's own
247+
JSON encoder, enabling the serialization of all types supplied by the schema.
248+
249+
.. change:: Fix OpenAPI schema generation for ``Literal`` and ``Enum`` unions with ``None``
250+
:type: bugfix
251+
:pr: 2550
252+
:issue: 2546
253+
254+
Existing behavior was to make the schema for every type that is a union with
255+
``None`` a ``"one_of"`` schema, that includes ``OpenAPIType.NULL`` in the
256+
``"one_of"`` types.
257+
258+
When a ``Literal`` or ``Enum`` type is in a union with ``None``, this behavior
259+
is not desirable, as we want to have ``null`` available in the list of available
260+
options on the type's schema.
261+
262+
This was fixed by modifying ``Literal`` and ``Enum`` schema generation so that i
263+
t can be identified that the types are in a union with ``None``, allowing
264+
``null`` to be included in ``Schema.enum`` values.
265+
266+
.. change:: Fix cache overrides when using same route with different handlers
267+
:type: bugfix
268+
:pr: 2592
269+
:issue: 2573, 2588
270+
271+
A bug was fixed that would cause the cache for routes being overwritten by a
272+
route handler on that same route with a different HTTP method.
273+
274+
275+
6276
.. changelog:: 2.2.0
7277
:date: 2023/10/12
8278

0 commit comments

Comments
 (0)