Skip to content

fix: check is_tuple_t before is_file_content in _transform_file#1416

Open
nileshpatil6 wants to merge 1 commit intoanthropics:mainfrom
nileshpatil6:fix/pathlike-in-file-tuples
Open

fix: check is_tuple_t before is_file_content in _transform_file#1416
nileshpatil6 wants to merge 1 commit intoanthropics:mainfrom
nileshpatil6:fix/pathlike-in-file-tuples

Conversation

@nileshpatil6
Copy link
Copy Markdown

Problem

_transform_file and _async_transform_file silently ignore PathLike objects in file upload tuples like ("foo.txt", Path("foo.txt"), "text/plain").

Root cause: is_file_content() returns True for any tuple (it does isinstance(obj, tuple)), so the is_tuple_t branch is unreachable when a tuple is passed in. The tuple is returned as-is without reading the PathLike contents, which breaks httpx serialization.

Fix

Swap the check order — test is_tuple_t first. Tuples then go through read_file_content(file[1]) (sync) / async_read_file_content(file[1]) (async), both of which already handle PathLike correctly.

Same fix applied to _async_transform_file.

Fixes #1318

is_file_content() returns True for any tuple (isinstance check), making the
is_tuple_t branch unreachable. Swapping the order ensures tuples like
(name, Path(...), mime_type) are routed through read_file_content() which
correctly reads PathLike contents.

Fixes anthropics#1318
@nileshpatil6 nileshpatil6 requested a review from a team as a code owner April 19, 2026 20:17
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.

[BUG] client.beta.files.upload PathLike error

1 participant