Skip to content

Commit 815901f

Browse files
authored
Clean up redundant code and stale comments from PR #11290 (#11301)
1 parent 57836c5 commit 815901f

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

aiohttp/payload.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,11 +557,7 @@ def size(self) -> Optional[int]:
557557
# By storing the start position, we ensure the size calculation always
558558
# returns the correct total size for any subsequent use.
559559
if self._start_position is None:
560-
try:
561-
self._start_position = self._value.tell()
562-
except (OSError, AttributeError):
563-
# Can't get position, can't determine size
564-
return None
560+
self._start_position = self._value.tell()
565561

566562
# Return the total size from the start position
567563
# This ensures Content-Length is correct even after reading

tests/test_client_functional.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5369,8 +5369,8 @@ async def test_file_upload_307_308_redirect(
53695369
) -> None:
53705370
"""Test that file uploads work correctly with 307/308 redirects.
53715371
5372-
This demonstrates the bug where file payloads get incorrect Content-Length
5373-
on redirect because the file position isn't reset.
5372+
This verifies that file payloads maintain correct Content-Length
5373+
on redirect by properly handling the file position.
53745374
"""
53755375
received_bodies: list[bytes] = []
53765376

tests/test_payload.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,8 +1281,9 @@ def open_file() -> TextIO:
12811281
async def test_iobase_payload_size_after_reading(tmp_path: Path) -> None:
12821282
"""Test that IOBasePayload.size returns correct size after file has been read.
12831283
1284-
This demonstrates the bug where size calculation doesn't account for
1285-
the current file position, causing issues with 307/308 redirects.
1284+
This verifies that size calculation properly accounts for the initial
1285+
file position, which is critical for 307/308 redirects where the same
1286+
payload instance is reused.
12861287
"""
12871288
# Create a test file with known content
12881289
test_file = tmp_path / "test.txt"
@@ -1304,14 +1305,12 @@ async def test_iobase_payload_size_after_reading(tmp_path: Path) -> None:
13041305
assert len(writer.buffer) == expected_size
13051306

13061307
# Second size check - should still return full file size
1307-
# but currently returns 0 because file position is at EOF
1308-
assert p.size == expected_size # This assertion fails!
1308+
assert p.size == expected_size
13091309

13101310
# Attempting to write again should write the full content
1311-
# but currently writes nothing because file is at EOF
13121311
writer2 = BufferWriter()
13131312
await p.write(writer2)
1314-
assert len(writer2.buffer) == expected_size # This also fails!
1313+
assert len(writer2.buffer) == expected_size
13151314
finally:
13161315
await asyncio.to_thread(f.close)
13171316

0 commit comments

Comments
 (0)