Skip to content

[CB-0] [sdk-superfan] Read PathLike content inside upload tuples - #221

Draft
spicysouvlaki wants to merge 1 commit into
mainfrom
wschmitt/pathlike-upload-tuples
Draft

spicysouvlaki wants to merge 1 commit into
mainfrom
wschmitt/pathlike-upload-tuples

Conversation

@spicysouvlaki

@spicysouvlaki spicysouvlaki commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

What happened

#196. A bare Path uploads, but file=("custom.zip", Path(...), "application/zip") fails with APIConnectionError: Connection error., caused by AttributeError: '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 tuple from is_file_content(), and have assert_is_file_content() accept tuples explicitly, since extract_files relies on it. This matches the upstream Stainless template (openai-python 90ac74ccf).

Tests

  • New test_pathlike_in_file_tuple and its async twin cover the 2-, 3- and 4-tuple shapes and extract_files. Before the fix: 6 failed. After: 30 passed.
  • Live run against api.dev.browserbase.com with extensions.create and a real pathlib.Path (measured). Before the fix, (name, Path) and (name, Path, ctype) failed with APIConnectionError, sync and async. After, all four uploads succeed with fileName=custom.zip. I deleted the test extensions.
  • ./scripts/lint: clean. ./scripts/test (py3.9 pydantic v2/v1, py3.14): all pass.
  • Not run: sessions.uploads.create live, because the dev key was at its concurrent-session limit. It goes through the same _files.py path.

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

`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

No deployments
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.

PathLike upload tuples fail with an opaque connection error

1 participant