Skip to content

Commit 96e030b

Browse files
committed
fix: ensure BodyPartReader.read() returns bytes instead of bytearray
The read() method's return type annotation promises bytes, but both the decoded and raw paths returned the internal bytearray buffer. This caused TypeError with json.dumps and other serializers that don't accept bytearray. Convert both return values to bytes() to match the documented API.
1 parent b0601d6 commit 96e030b

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

aiohttp/multipart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ async def read(self, *, decode: bool = False) -> bytes:
322322
decoded_data.extend(d)
323323
if len(decoded_data) > self._client_max_size:
324324
raise self._max_size_error_cls(self._client_max_size)
325-
return decoded_data
326-
return data
325+
return bytes(decoded_data)
326+
return bytes(data)
327327

328328
async def read_chunk(self, size: int = chunk_size) -> bytes:
329329
"""Reads body part content chunk of the specified size.

0 commit comments

Comments
 (0)