Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix StreamResponse.prepared not returning True after EOF is sent #5344

Merged
merged 4 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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/5343.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed StreamResponse.prepared to return True after EOF is sent -- by :user:`arthurdarcet`.
2 changes: 1 addition & 1 deletion aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def __init__(

@property
def prepared(self) -> bool:
return self._payload_writer is not None
return self._eof_sent or self._payload_writer is not None

@property
def task(self) -> "Optional[asyncio.Task[None]]":
Expand Down
15 changes: 10 additions & 5 deletions tests/test_web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,11 +734,8 @@ async def test___repr___after_eof() -> None:
resp = StreamResponse()
await resp.prepare(make_request("GET", "/"))

assert resp.prepared

await resp.write(b"data")
await resp.write_eof()
assert not resp.prepared
resp_repr = repr(resp)
assert resp_repr == "<StreamResponse OK eof>"

Expand Down Expand Up @@ -1110,14 +1107,22 @@ def test_content_type_with_set_body() -> None:
assert resp.content_type == "application/octet-stream"


def test_started_when_not_started() -> None:
def test_prepared_when_not_started() -> None:
resp = StreamResponse()
assert not resp.prepared


async def test_started_when_started() -> None:
async def test_prepared_when_started() -> None:
resp = StreamResponse()
await resp.prepare(make_request("GET", "/"))
assert resp.prepared


async def test_prepared_after_eof() -> None:
resp = StreamResponse()
await resp.prepare(make_request("GET", "/"))
await resp.write(b"data")
await resp.write_eof()
assert resp.prepared


Expand Down
Loading