Skip to content

Commit 0d4fe01

Browse files
authored
fix: change URL.with_replacements to use Empty (#2482)
1 parent 0767072 commit 0d4fe01

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

litestar/datastructures/url.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def with_replacements(
200200
scheme: str = "",
201201
netloc: str = "",
202202
path: str = "",
203-
query: str | MultiDict | None = None,
203+
query: str | MultiDict | None | EmptyType = Empty,
204204
fragment: str = "",
205205
) -> URL:
206206
"""Create a new URL, replacing the given components.
@@ -217,12 +217,13 @@ def with_replacements(
217217
"""
218218
if isinstance(query, MultiDict):
219219
query = urlencode(query=query)
220+
query = (query if query is not Empty else self.query) or ""
220221

221222
return URL.from_components( # type: ignore[no-any-return]
222223
scheme=scheme or self.scheme,
223224
netloc=netloc or self.netloc,
224225
path=path or self.path,
225-
query=query or self.query,
226+
query=query,
226227
fragment=fragment or self.fragment,
227228
)
228229

tests/unit/test_datastructures/test_url.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def test_url_from_components(component: str, value: str) -> None:
6060
("scheme", "http", "http"),
6161
("netloc", "example.com", "example.com"),
6262
("path", "/foo", "/foo"),
63+
("query", None, ""),
64+
("query", "", ""),
65+
("query", MultiDict({}), ""),
6366
("query", "foo=baz", "foo=baz"),
6467
("query", MultiDict({"foo": "baz"}), "foo=baz"),
6568
("fragment", "anchor2", "anchor2"),

0 commit comments

Comments
 (0)