Skip to content

fix(files): read PathLike contents in upload tuples - #3782

Open
Hughhhhcoder wants to merge 2 commits into
openai:mainfrom
Hughhhhcoder:codex/openai-python-pathlike-upload
Open

fix(files): read PathLike contents in upload tuples#3782
Hughhhhcoder wants to merge 2 commits into
openai:mainfrom
Hughhhhcoder:codex/openai-python-pathlike-upload

Conversation

@Hughhhhcoder

Copy link
Copy Markdown

Summary

Fixes #3473.

FileTypes documents PathLike values inside multipart upload tuples, but _transform_file and _async_transform_file classify a tuple as file content before they normalize its content element. As a result, a value such as ("custom.txt", Path("input.jsonl")) is passed to httpx with the PathLike object still present instead of its bytes.

This change handles upload tuples before direct file contents, so the existing sync and async read_file_content helpers convert tuple contents consistently while preserving the filename and optional metadata.

Reproduction

Before this change, both of these returned a tuple containing the original Path object:

from pathlib import Path
from openai._files import async_to_httpx_files, to_httpx_files

to_httpx_files({"file": ("custom.txt", Path("input.jsonl"))})
await async_to_httpx_files({"file": ("custom.txt", Path("input.jsonl"))})

Validation

  • PYTHONPATH=src .venv/bin/python -m pytest tests/test_multipart_encoding.py tests/test_files.py (21 passed)
  • ruff check src/openai/_files.py tests/test_files.py
  • ruff format --check src/openai/_files.py tests/test_files.py
  • git diff --check

@Hughhhhcoder
Hughhhhcoder requested a review from a team as a code owner September 2, 2026 10:58
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-04T11:53:17.409350Z d038f3a Manual request
🔒 Security Review ⚠️ Failed 2026-09-04T11:51:10.158379Z d038f3a Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Checked the branch ordering here: is_file_content() also classifies tuples as file content, so the old order swallowed multipart tuples before their inner PathLike could be normalized. Handling tuples first fixes that in both sync and async paths, while preserving the filename and any trailing content-type/header fields. This looks scoped correctly.

@Hughhhhcoder

Copy link
Copy Markdown
Author

Thanks for tracing the tuple classification order through both sync and async upload paths. The current head preserves the tuple metadata while normalizing the inner PathLike, and the focused regression coverage passes.

@Hughhhhcoder

Copy link
Copy Markdown
Author

Synced this branch with the latest upstream main (3cc8d784) using a regular merge (no force-push); current head is d038f3a8.

Validation after the sync:

  • uv run --locked pytest tests/test_files.py: 16 passed
  • Ruff check and format check on changed Python files: passed
  • git diff --check origin/main...HEAD: passed

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Provided git ref d038f3a8a31fbd5b9d828826ed9580cae443a48b does not exist
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: d038f3a8a3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

PathLike file contents fail when passed inside upload tuples

2 participants