Skip to content

Fix memoryview payload serialization and byte-length limits - #14019

Open
Vaishnavi220506 wants to merge 2 commits into
aio-libs:masterfrom
Vaishnavi220506:Vaishnavi220506/fix-memoryview-payloads
Open

Vaishnavi220506 wants to merge 2 commits into
aio-libs:masterfrom
Vaishnavi220506:Vaishnavi220506/fix-memoryview-payloads

Conversation

@Vaishnavi220506

@Vaishnavi220506 Vaishnavi220506 commented Oct 13, 2026 •

Copy link
Copy Markdown

What do these changes do?

Fix BytesPayload serialization for memoryviews whose elements or dimensions are not individual bytes. Normalize contiguous views to a flat byte view without copying, and materialize non-contiguous or empty views as bytes. decode() and as_bytes() now work for all accepted buffer types.

For example, writing BytesPayload(memoryview(b"abcdefgh").cast("H")) with a length limit of 3 currently writes 6 bytes. A (2, 4) view writes all 8 bytes instead, and a scalar view raises TypeError. All three now honor the limit in bytes. Calling decode() on any memoryview previously raised AttributeError.

Regression tests cover typed, multidimensional, strided, scalar, and empty views; a mutable-buffer test checks that contiguous views remain live. HTTP round trips exercise both request uploads and response bodies.

Local validation

Base: 708528592b1a8fdfc1cbe0d81fe4417693f0bb5d. The regression run produced 17 failures and 27 passes before the production fix.

Windows, CPython 3.14.3, pure Python:

AIOHTTP_NO_EXTENSIONS=1 python -X dev -m pytest -p no:aiohttp -o addopts='' tests/test_payload.py tests/test_client_functional.py tests/test_multipart.py tests/test_http_writer.py tests/test_web_response.py -q --tb=short --timeout=15
938 passed, 67 skipped, 1 xfailed

All applicable pre-commit run --files aiohttp/payload.py tests/test_payload.py tests/test_client_functional.py CONTRIBUTORS.txt CHANGES/70852859.bugfix.rst hooks passed in a Linux checkout of the same patch. The hook environments needed setuptools<81 for the repository's flake8-requirements plugin.

The full suite and compiled extensions were not run.

mypy aiohttp/payload.py on Linux with CPython 3.12.3 reports the same three errors on upstream and this patch, in compression_utils.py and client_reqrep.py; none are in the changed module.

Are there changes in behavior for the user?

Byte limits apply to bytes regardless of a view's format or shape. Strided and scalar payloads can be transmitted, memoryviews can be decoded, and as_bytes() returns bytes for bytearray and memoryview inputs as its return annotation specifies. Non-contiguous views are snapshotted at construction; contiguous views still reflect buffer mutations.

Is it a substantial burden for the maintainers to support this?

No new dependencies or API parameters. Buffer normalization stays in the existing BytesPayload constructor, so its consumers share the fix.

Related issue number

N/A — found through local reproduction.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes — corrected as_bytes() docstring and added a news fragment
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
  • Add a new news fragment into the CHANGES/ folder

Drafted with OpenAI Codex (GPT-6); reviewed by @Vaishnavi220506.

@agentscanapp

agentscanapp Bot commented Oct 13, 2026

Copy link
Copy Markdown

@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Oct 13, 2026
@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.10%. Comparing base (7085285) to head (ec2b821).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #14019      +/-   ##
==========================================
- Coverage   99.10%   99.10%   -0.01%     
==========================================
  Files         135      135              
  Lines       53551    53600      +49     
  Branches     2809     2811       +2     
==========================================
+ Hits        53071    53118      +47     
- Misses        362      363       +1     
- Partials      118      119       +1     
Flag Coverage Δ
Autobahn 21.69% <19.60%> (-0.01%) ⬇️
CI-GHA 98.93% <100.00%> (-0.01%) ⬇️
OS-Linux 98.73% <100.00%> (-0.01%) ⬇️
OS-Windows 97.37% <100.00%> (-0.01%) ⬇️
OS-macOS 98.24% <100.00%> (-0.02%) ⬇️
Py-3.10 98.17% <100.00%> (+<0.01%) ⬆️
Py-3.11 98.40% <100.00%> (+<0.01%) ⬆️
Py-3.12 98.49% <100.00%> (+<0.01%) ⬆️
Py-3.13 98.48% <100.00%> (-0.01%) ⬇️
Py-3.14 98.51% <100.00%> (-0.01%) ⬇️
Py-3.15 98.51% <100.00%> (-0.01%) ⬇️
Py-3.15t 97.90% <100.00%> (-0.01%) ⬇️
Py-pypy-3.12 96.57% <100.00%> (+<0.01%) ⬆️
VM-macos 98.24% <100.00%> (-0.02%) ⬇️
VM-ubuntu 98.73% <100.00%> (-0.01%) ⬇️
VM-windows 97.37% <100.00%> (-0.01%) ⬇️
cython-coverage 83.58% <86.36%> (+<0.01%) ⬆️

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

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

@codspeed

codspeed Bot commented Oct 13, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 49 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 102 untouched benchmarks
⏩ 83 skipped benchmarks1


Comparing Vaishnavi220506:Vaishnavi220506/fix-memoryview-payloads (ec2b821) with master (7085285)

Open in CodSpeed

Footnotes

  1. 83 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. ↩

@Vaishnavi220506
Vaishnavi220506 marked this pull request as ready for review October 13, 2026 04:54
@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] No blocking issues were found; the reviewed changes are safe to merge within the checked pure-Python scope.

T-Rex evidence

Evidence from the check

  • This exact Python source was executed against base and head to test buffer representations, byte limits, live views, and HTTP round trips; its observations are captured in the paired probe logs.

Evidence from the check

  • This exact shell script ran the probe and pytest checks with the prepared interpreter and captured command, working directory, exit code, and output; both revisions used the same validation scope.

Command output from the check

  • Ran the authored probe against base and captured structured payload checks, endpoint statuses, and connection failures; 118 of 180 checks passed.

Command output from the check

  • Ran the identical probe against head and captured exact bytes, types, lengths, and HTTP statuses; all 180 checks passed and all 32 requests returned 200 OK.

Command output from the check

  • Executed the same 44 selected head regressions against base production code and captured full pytest failure output; 17 failed and 27 passed.

Command output from the check

  • Executed the 44 selected payload and HTTP regressions against head and captured pytest output; all 44 passed.

Command output from the check

  • Executed head's payload test file against base production code and captured full pytest output; 15 failed and 99 passed.

Command output from the check

  • Executed the complete payload test file against head and captured pytest output; all 114 tests passed.

Command output from the check

  • Ran the new five-case functional test against parent source and captured two upload failures alongside three passes, establishing the pre-change baseline.

Command output from the check

  • Ran the requested functional test against the PR source with the prepared interpreter and captured five passes, showing every tested round trip succeeds.

Evidence from the check

  • Executed this same local-server probe against parent and PR source to record HTTP statuses, lengths, body bytes, and exceptions, making the comparison reproducible.

Command output from the check

  • Captured ten endpoint attempts against parent source with full HTTP status lines where available and exceptions otherwise, exposing the existing strided and scalar upload failures.

Command output from the check

  • Captured the same ten endpoint attempts against PR source with 200 OK responses and matching Content-Length and bytes throughout, showing no tested transport regression.

View artifacts

Reviews (1) · Last reviewed commit: "Name the news fragment after PR 14019" · Reviewed by Greptile

This branch has not been deployed

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

Labels

agentscan:automation-signals bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant