Skip to content

Fix BodyPartReader.read() returning bytearray instead of bytes#12466

Open
mitre88 wants to merge 1 commit intoaio-libs:masterfrom
mitre88:fix/bodyreader-bytearray-leak
Open

Fix BodyPartReader.read() returning bytearray instead of bytes#12466
mitre88 wants to merge 1 commit intoaio-libs:masterfrom
mitre88:fix/bodyreader-bytearray-leak

Conversation

@mitre88
Copy link
Copy Markdown
Contributor

@mitre88 mitre88 commented May 5, 2026

BodyPartReader.read() was returning the internal bytearray buffer directly instead of bytes, violating the annotated return type of bytes.

This caused TypeError: Object of type bytearray is not JSON serializable when downstream code (like json.dump) tried to serialize the value.

The fix wraps the return values with bytes() to match the annotated return type.

Fixes #12404

BodyPartReader.read() was returning the internal bytearray buffer
directly instead of bytes, violating the annotated return type.

This caused TypeError when downstream code (like json.dump)
tried to serialize the value since bytearray is not JSON serializable.

The fix wraps the return values with bytes() to match the
annotated return type.

Fixes aio-libs#12404
@mitre88 mitre88 requested a review from asvetlov as a code owner May 5, 2026 22:19
@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.92%. Comparing base (0471d65) to head (ddf2785).
⚠️ Report is 2 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #12466   +/-   ##
=======================================
  Coverage   98.92%   98.92%           
=======================================
  Files         134      134           
  Lines       46750    46750           
  Branches     2429     2429           
=======================================
  Hits        46248    46248           
  Misses        373      373           
  Partials      129      129           
Flag Coverage Δ
CI-GHA 98.98% <100.00%> (ø)
OS-Linux 98.72% <100.00%> (-0.01%) ⬇️
OS-Windows 96.98% <100.00%> (ø)
OS-macOS 97.89% <100.00%> (+<0.01%) ⬆️
Py-3.10.11 97.39% <100.00%> (ø)
Py-3.10.20 97.86% <100.00%> (+<0.01%) ⬆️
Py-3.11.15 98.11% <100.00%> (ø)
Py-3.11.9 97.64% <100.00%> (-0.01%) ⬇️
Py-3.12.10 97.74% <100.00%> (+<0.01%) ⬆️
Py-3.12.13 98.20% <100.00%> (+<0.01%) ⬆️
Py-3.13.13 98.44% <100.00%> (-0.01%) ⬇️
Py-3.14.4 98.51% <100.00%> (ø)
Py-3.14.4t 97.51% <100.00%> (ø)
Py-pypy3.11.15-7.3.21 97.35% <100.00%> (ø)
VM-macos 97.89% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 98.72% <100.00%> (-0.01%) ⬇️
VM-windows 96.98% <100.00%> (ø)
cython-coverage 38.08% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 5, 2026

Merging this PR will not alter performance

✅ 67 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing mitre88:fix/bodyreader-bytearray-leak (ddf2785) with master (0471d65)2

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on master (0f0b0e5) during the generation of this report, so 0471d65 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: BodyPartReader.filename and read() leak bytearray instead of str/bytes, violating API contract and breaking JSON serialization

1 participant