Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/10146.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Setting :attr:`aiohttp.web.StreamResponse.last_modified` to an unsupported type will now raise :exc:`ValueError` instead of silently failing -- by :user:`bdraco`.
3 changes: 3 additions & 0 deletions aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ def last_modified(
)
elif isinstance(value, str):
self._headers[hdrs.LAST_MODIFIED] = value
else:
msg = f"Unsupported type for last_modified: {type(value).__name__}" # type: ignore[unreachable]
raise ValueError(msg)

@property
def etag(self) -> Optional[ETag]:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ def test_last_modified_reset() -> None:
assert resp.last_modified is None


def test_last_modified_invalid_type() -> None:
resp = web.StreamResponse()

with pytest.raises(ValueError, match="Unsupported type for last_modified: object"):
resp.last_modified = object() # type: ignore[assignment]


@pytest.mark.parametrize(
"header_val",
(
Expand Down
Loading