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
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