Skip to content

fix: read PathLike content inside upload tuples - #3614

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

fix: read PathLike content inside upload tuples#3614
jstar0 wants to merge 1 commit into
openai:mainfrom
jstar0:fix/pathlike-upload-tuples

Conversation

@jstar0

@jstar0 jstar0 commented Aug 14, 2026

Copy link
Copy Markdown

Summary

  • Read PathLike file contents when they are passed as the content element of multipart upload tuples.
  • Preserve the caller-provided filename, content type, and extra tuple fields.
  • Add sync and async regression coverage for tuple uploads.

Fixes #3473.

Verification

  • uv run --with pytest --with pytest-asyncio --with dirty-equals python -m pytest tests/test_files.py tests/test_extract_files.py -q -o addopts=
  • uv run --with ruff ruff check src/openai/_files.py tests/test_files.py
  • uv run --with ruff ruff format --check src/openai/_files.py tests/test_files.py
  • uv run --with pyright --with pytest --with pytest-asyncio --with dirty-equals scripts/run-pyright src/openai/_files.py tests/test_files.py
  • uv run python -c "import openai; print(openai.__version__)"

@jstar0
jstar0 requested a review from a team as a code owner August 14, 2026 03:30

@ting-hong-shieh ting-hong-shieh 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.

I'm requesting changes because the production patch is identical to #3474 and carries forward the boundary problem already identified in that review.

is_file_content() is declared as TypeGuard[FileContent], but it returns True for tuples even though _types.py defines FileContent as IO[bytes] | bytes | PathLike and models upload tuples separately in FileTypes. Moving the tuple branch ahead of that predicate makes the reported PathLike case pass, but it leaves the type guard unsound and makes correctness depend on branch order.

Please make is_file_content() match the FileContent alias, then update assert_is_file_content() to accept and validate the supported tuple forms explicitly (or add a separate, correctly typed FileTypes predicate). Since #3474 already tracks this implementation for #3473, consolidating the correction there would keep the issue on one implementation path.

Validated at exact head bc52b78f11a8f71866f1126bf562c981e272e0d7 against base/current main d9029e3ada3c008b4631d78a425743445730892a:

  • tests/test_files.py and tests/test_extract_files.py: 26 passed.
  • Ruff lint and format checks passed on both changed files.
  • Pyright passed with 0 errors.
  • git diff --check passed.
  • src/openai/_files.py is identical to the current #3474 head, where the same predicate correction remains requested.

No API call, credential, or external service was used.

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