Skip to content

fix: handle single-element tuple in file upload#1356

Open
lui62233 wants to merge 1 commit intoanthropics:mainfrom
lui62233:fix-file-tuple-length
Open

fix: handle single-element tuple in file upload#1356
lui62233 wants to merge 1 commit intoanthropics:mainfrom
lui62233:fix-file-tuple-length

Conversation

@lui62233
Copy link
Copy Markdown

Summary

When passing a single-element tuple like (pathlib.Path("/path/to/file"),) as a file argument to client.beta.files.upload, the SDK crashes with IndexError: tuple index out of range because _transform_file unconditionally accesses file[1] without checking tuple length.

Fix

In _transform_file and _async_transform_file, add a length check before treating a tuple as a (filename, content) pair. Single-element tuples are now correctly treated as (None, content).

Fixes #1318

@lui62233 lui62233 requested a review from a team as a code owner April 10, 2026 02:38
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