Repository navigation
[CB-0] [sdk-superfan] Read PathLike content inside upload tuples - #221
Draft
spicysouvlaki wants to merge 1 commit into
Draft
spicysouvlaki wants to merge 1 commit into
spicysouvlaki wants to merge 1 commit into
Conversation
`is_file_content()` returned True for any tuple, so `_transform_file()` and
`_async_transform_file()` took the "already file content" branch and handed
`("custom.md", Path(...), "text/markdown")` to httpx unchanged. httpx then
called `.read()` on the Path, raising AttributeError, which the client wraps
as `APIConnectionError: Connection error.`
Reproduced against api.dev.browserbase.com with `extensions.create`: a bare
Path uploads, while `(name, Path)` and `(name, Path, ctype)` (sync and async)
fail with APIConnectionError caused by
`AttributeError: 'PosixPath' object has no attribute 'read'`. With this
change all four upload and keep the custom filename (`fileName=custom.zip`).
Fix: drop `tuple` from `is_file_content()` so tuples reach the existing
tuple branch that reads PathLike via `read_file_content()`, and let
`assert_is_file_content()` (used by `extract_files`) keep accepting tuples.
This is the same change Stainless shipped upstream in openai-python
90ac74ccf "fix(files): normalize PathLike upload tuples", so the sealed
edit should match the template when this repo next picks up core updates.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
What happened
#196. A bare
Pathuploads, butfile=("custom.zip", Path(...), "application/zip")fails withAPIConnectionError: Connection error., caused byAttributeError: 'PosixPath' object has no attribute 'read'.Why
is_file_content()returns True for any tuple (_files.py:30-33). So_transform_file()returns the tuple unchanged at L66-71 and never reaches the tuple branch at L73-74 that reads the Path. httpx then calls.read()on the Path.Fix
Remove
tuplefromis_file_content(), and haveassert_is_file_content()accept tuples explicitly, sinceextract_filesrelies on it. This matches the upstream Stainless template (openai-python90ac74ccf).Tests
test_pathlike_in_file_tupleand its async twin cover the 2-, 3- and 4-tuple shapes andextract_files. Before the fix: 6 failed. After: 30 passed.api.dev.browserbase.comwithextensions.createand a realpathlib.Path(measured). Before the fix,(name, Path)and(name, Path, ctype)failed with APIConnectionError, sync and async. After, all four uploads succeed withfileName=custom.zip. I deleted the test extensions../scripts/lint: clean../scripts/test(py3.9 pydantic v2/v1, py3.14): all pass.sessions.uploads.createlive, because the dev key was at its concurrent-session limit. It goes through the same_files.pypath.Risk and rollout
This is a sealed edit to the generated
_files.py. It should match the Stainless template once this repo picks up newer core files, so a regen conflict is unlikely (inferred). It ships with the next SDK release, and the API is unaffected.Fixes #196
🤖 Generated with Claude Code