Count Azure writer memoryview inputs in bytes by zhechen-cs · Pull Request #965 · piskvorky/smart_open · GitHub
Skip to content

Count Azure writer memoryview inputs in bytes - #965

Merged
ddelange merged 1 commit into
piskvorky:developfrom
zhechen-cs:codex/azure-buffer-byte-count
Oct 12, 2026
Merged

ddelange merged 1 commit into
piskvorky:developfrom
zhechen-cs:codex/azure-buffer-byte-count

Conversation

@zhechen-cs

Copy link
Copy Markdown
Contributor

Motivation

Azure block and append writers accept typed and multidimensional memoryview inputs, but count their elements instead of their bytes. Writing a 16-byte buffer cast to I uploads all 16 bytes while write() returns 4 and tell() reports 4; a 2-by-2 view reports 2. This breaks the byte-count contract for callers streaming array buffers to Azure Blob Storage.

Use the byte count returned by the underlying BytesIO.write() for both writers. The upload contents and buffering thresholds are unchanged. Found during source inspection and reproduced on unmodified develop (418d3ee).

Tests

The regression covers block and append modes, buffered and immediately uploaded parts, consecutive writes, and bytes, bytearray, byte views, integer views and multidimensional views. It compares write() and tell() with BytesIO, then reads back the uploaded bytes through the public API.

  • On unmodified source: 8 regression cases failed, 12 controls passed.
  • python -m pytest tests/ -q: 492 passed, 4 skipped.
  • make lint: all checks passed (including Ruff, ty and pydoclint).

Azure coverage uses the repository's in-memory fake client; no live Azure service was tested. The four skips are the missing-dependency environment checks and the test requiring a local Moto server.

Checklist

  • Picked a concise, informative and complete title
  • Clearly explained the motivation behind the PR
  • Linked to any existing issues that your PR will be solving (no existing issue found)
  • Included tests for any new functionality
  • Run python update_helptext.py in case there are API changes (not applicable; no API changes)
  • Checked that all unit tests pass (492 passed; 4 environment-dependent skips)

@ddelange ddelange left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ddelange
ddelange merged commit 1cc5f66 into piskvorky:develop Oct 12, 2026
6 checks passed
@github-actions

Copy link
Copy Markdown

ddelange added a commit that referenced this pull request Oct 28, 2026
* [s3] Count S3 multipart writer memoryview inputs in bytes

MultipartWriter.write wrapped its argument in memoryview(b) without a
byte cast, so for a typed buffer (memoryview.cast('I'), array('d'))
write() returned and tell() reported the number of elements, and parts
were cut every part_size elements rather than bytes. Cast to bytes, as
the S3 reader already does and as #965/#971 did for Azure and WebHDFS.

* Test that a rejected multipart write leaves close working

---------

Co-authored-by: youdie006 <youdie006@users.noreply.github.com>
Co-authored-by: ddelange <14880945+ddelange@users.noreply.github.com>
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.

2 participants