fix(files): check is_tuple_t before is_file_content to fix PathLike inside file tuples#1322
Open
IgnazioDS wants to merge 1 commit intoanthropics:mainfrom
Open
fix(files): check is_tuple_t before is_file_content to fix PathLike inside file tuples#1322IgnazioDS wants to merge 1 commit intoanthropics:mainfrom
IgnazioDS wants to merge 1 commit intoanthropics:mainfrom
Conversation
…ke in tuples (anthropics#1318) is_file_content() returns True for tuples (bytes|tuple|io.IOBase|PathLike), so the is_tuple_t branch in _transform_file and _async_transform_file was unreachable. Any caller passing a file tuple whose second element is a PathLike — e.g. ("filename.txt", Path("foo.txt"), "text/plain") — would hit the is_file_content branch first, which returns the tuple unchanged without ever calling read_file_content on the PathLike. Fix: swap the guard order so is_tuple_t is checked first in both the sync and async paths. The PathLike is then correctly read via read_file_content / async_read_file_content before being forwarded to httpx. Fixes anthropics#1318
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1318 —
client.beta.files.uploadcrashes when aPathLikeis passed as the second element of a file tuple (e.g.("filename.txt", Path("foo.txt"), "text/plain")).Root cause:
is_file_content()returnsTruefor anytuple, so theis_tuple_tbranch in both_transform_fileand_async_transform_filewas unreachable. A file tuple hit theis_file_contentbranch first and was returned unchanged — thePathLikeinside was never read viaread_file_content.Fix: Check
is_tuple_tfirst in both the sync and async paths, so tuples withPathLikesecond elements are correctly read before being forwarded to httpx.Same fix applied to
_async_transform_filewithasync_read_file_content.Test plan
("filename.txt", Path("foo.txt"), "text/plain")— PathLike read, no crash("filename.txt", Path("foo.txt"))— 2-tuple variant worksPath("foo.txt")bare PathLike — still works (goes throughis_file_contentbranch)("filename.txt", b"bytes", "text/plain")— bytes tuple still workspytest tests/test_files.py