From 21913be4093558dc3469e482d3cadd422e0ad227 Mon Sep 17 00:00:00 2001 From: armorbreak001 Date: Wed, 22 Apr 2026 23:07:46 +0800 Subject: [PATCH] fix(multipart): ensure BodyPartReader.read() returns bytes not bytearray The read() method built its result in a bytearray but returned it directly, violating the documented return type of bytes. This caused TypeError when passing the result to json.dumps() or other APIs that expect bytes but not bytearray. --- aiohttp/multipart.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aiohttp/multipart.py b/aiohttp/multipart.py index 9d5e5d27b84..4d4eee7887f 100644 --- a/aiohttp/multipart.py +++ b/aiohttp/multipart.py @@ -322,8 +322,8 @@ async def read(self, *, decode: bool = False) -> bytes: decoded_data.extend(d) if len(decoded_data) > self._client_max_size: raise self._max_size_error_cls(self._client_max_size) - return decoded_data - return data + return bytes(decoded_data) + return bytes(data) async def read_chunk(self, size: int = chunk_size) -> bytes: """Reads body part content chunk of the specified size.