File tree Expand file tree Collapse file tree 3 files changed +8
-13
lines changed Expand file tree Collapse file tree 3 files changed +8
-13
lines changed Original file line number Diff line number Diff line change @@ -557,11 +557,7 @@ def size(self) -> Optional[int]:
557
557
# By storing the start position, we ensure the size calculation always
558
558
# returns the correct total size for any subsequent use.
559
559
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 ()
565
561
566
562
# Return the total size from the start position
567
563
# This ensures Content-Length is correct even after reading
Original file line number Diff line number Diff line change @@ -5369,8 +5369,8 @@ async def test_file_upload_307_308_redirect(
5369
5369
) -> None :
5370
5370
"""Test that file uploads work correctly with 307/308 redirects.
5371
5371
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.
5374
5374
"""
5375
5375
received_bodies : list [bytes ] = []
5376
5376
Original file line number Diff line number Diff line change @@ -1281,8 +1281,9 @@ def open_file() -> TextIO:
1281
1281
async def test_iobase_payload_size_after_reading (tmp_path : Path ) -> None :
1282
1282
"""Test that IOBasePayload.size returns correct size after file has been read.
1283
1283
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.
1286
1287
"""
1287
1288
# Create a test file with known content
1288
1289
test_file = tmp_path / "test.txt"
@@ -1304,14 +1305,12 @@ async def test_iobase_payload_size_after_reading(tmp_path: Path) -> None:
1304
1305
assert len (writer .buffer ) == expected_size
1305
1306
1306
1307
# 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
1309
1309
1310
1310
# Attempting to write again should write the full content
1311
- # but currently writes nothing because file is at EOF
1312
1311
writer2 = BufferWriter ()
1313
1312
await p .write (writer2 )
1314
- assert len (writer2 .buffer ) == expected_size # This also fails!
1313
+ assert len (writer2 .buffer ) == expected_size
1315
1314
finally :
1316
1315
await asyncio .to_thread (f .close )
1317
1316
You can’t perform that action at this time.
0 commit comments