fix: check is_tuple_t before is_file_content in _transform_file#1416
Open
nileshpatil6 wants to merge 1 commit intoanthropics:mainfrom
Open
fix: check is_tuple_t before is_file_content in _transform_file#1416nileshpatil6 wants to merge 1 commit intoanthropics:mainfrom
nileshpatil6 wants to merge 1 commit intoanthropics:mainfrom
Conversation
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
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.
Problem
_transform_fileand_async_transform_filesilently ignorePathLikeobjects in file upload tuples like("foo.txt", Path("foo.txt"), "text/plain").Root cause:
is_file_content()returnsTruefor any tuple (it doesisinstance(obj, tuple)), so theis_tuple_tbranch is unreachable when a tuple is passed in. The tuple is returned as-is without reading thePathLikecontents, which breakshttpxserialization.Fix
Swap the check order — test
is_tuple_tfirst. Tuples then go throughread_file_content(file[1])(sync) /async_read_file_content(file[1])(async), both of which already handlePathLikecorrectly.Same fix applied to
_async_transform_file.Fixes #1318