fix(files): read PathLike contents in upload tuples - #3782
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
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.
|
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 |
|
Synced this branch with the latest upstream Validation after the sync:
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Summary
Fixes #3473.
FileTypesdocumentsPathLikevalues inside multipart upload tuples, but_transform_fileand_async_transform_fileclassify 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 thePathLikeobject still present instead of its bytes.This change handles upload tuples before direct file contents, so the existing sync and async
read_file_contenthelpers convert tuple contents consistently while preserving the filename and optional metadata.Reproduction
Before this change, both of these returned a tuple containing the original
Pathobject: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.pyruff format --check src/openai/_files.py tests/test_files.pygit diff --check