Skip to content

fix(files): support PathLike objects inside upload tuples - #3546

Open
Rajeev91691 wants to merge 1 commit into
openai:mainfrom
Rajeev91691:fix/pathlike-upload-tuples
Open

fix(files): support PathLike objects inside upload tuples#3546
Rajeev91691 wants to merge 1 commit into
openai:mainfrom
Rajeev91691:fix/pathlike-upload-tuples

Conversation

@Rajeev91691

Copy link
Copy Markdown

Summary

This PR fixes a bug where PathLike objects passed inside custom upload tuples (e.g. ("custom_name.txt", Path("file.txt"))) were not normalized to bytes, causing httpx to raise an AttributeError at runtime (see #3473).

Changes

  1. src/openai/_files.py:
    • Excluded tuple from is_file_content so that custom upload tuples fall through to the is_tuple_t block in _transform_file and _async_transform_file, which successfully normalizes the nested PathLike object.
    • Updated assert_is_file_content to check for is_file_content(obj) or isinstance(obj, tuple) to preserve tuple input validation.
  2. tests/test_files.py:
    • Added test_tuple_in_mapping_normalizes_path and test_async_tuple_in_mapping_normalizes_path to verify the fix for both sync and async paths.

All 16 file tests pass successfully.

@Rajeev91691
Rajeev91691 requested a review from a team as a code owner July 28, 2026 06:07

@jbeckwith-oai jbeckwith-oai 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.

Reviewed the tuple normalization path and extraction validation behavior. This correctly restores the distinction between raw file content and multipart tuples, routes tuple contents through the existing sync/async PathLike readers, and preserves tuple acceptance during file extraction. The focused tests fail on the base commit and pass on this head; the full repository lint/typecheck/import gate and file tests are clean.

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