Skip to content

Don't use the file descriptor size for multipart file lengths - #1320

Open
patrick-immometrica wants to merge 1 commit into
pydantic:mainfrom
patrick-immometrica:multipart-file-length
Open

patrick-immometrica wants to merge 1 commit into
pydantic:mainfrom
patrick-immometrica:multipart-file-length

Conversation

@patrick-immometrica

@patrick-immometrica patrick-immometrica commented Nov 8, 2026 •

Copy link
Copy Markdown

Summary

peek_filelike_length() takes os.fstat().st_size when the object has a fileno(). That's wrong for anything where read() doesn't return the raw file bytes:

  • gzip.open(path, "rb") reports the compressed size
  • a pipe (Popen(...).stdout, sys.stdin.buffer) reports 0

So files={"f": gzip.open(...)} sends a too small Content-Length and fails with LocalProtocolError: Too much data for declared Content-Length.

This drops the fstat branch and keeps the tell()/seek() fallback, the same thing #1214 did for content=. Gzip files now get the right length, pipes go out chunked. Regular files are unchanged.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

View guided diff

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files

Reply to a comment to ask cubic a question or push back. It learns from your replies.

View guided diff | Re-trigger cubic

Comment thread src/httpx2/httpx2/_utils.py Resolved
@codspeed

codspeed Bot commented Nov 8, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 17 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing patrick-immometrica:multipart-file-length (6efb783) with main (f4f65c1)

Open in CodSpeed

Footnotes

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

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant