Skip to content

fix(python): Fix python wire tests - #11284

Merged
jsklan merged 20 commits into
mainfrom
jsklan/fix-box-python
Jan 8, 2026
Merged

jsklan merged 20 commits into
mainfrom
jsklan/fix-box-python

Conversation

@jsklan

@jsklan jsklan commented Dec 17, 2025 •

Copy link
Copy Markdown
Contributor

Description

Fixes several bugs preventing Python SDK wire test generation from working correctly with some custom APIs. These issues caused mypy validation failures and runtime errors when running generated wire tests.

Changes Made

  • String escaping: Rewrote escapeString in TypeInstantiation.ts to escape backslashes first, fixing double-escaping issues with JSON examples containing \" sequences
  • Environment configuration: Updated WireTestSetupGenerator to detect single/multiple base URL environments and generate appropriate environment=ClientEnvironment(...) params instead of hardcoded base_url
  • Error response handling: Wire tests now wrap error responses (non-2xx) in pytest.raises(ApiError) instead of failing on expected exceptions
  • Streaming responses: Added list() wrapper for streaming endpoints (fileDownload, bytes, streaming) to consume iterators and trigger HTTP requests
  • URL fragments: Strip URL fragments before HTTP requests in both mock-utils and WireTestGenerator (fragments like #refresh are never sent to servers)
  • Python 3.8 datetime: Convert ISO datetime 'Z' suffix to '+00:00' for datetime.fromisoformat() compatibility
  • Multipart form serialization (Python v1): JSON serialize complex types in file upload body properties for httpx multipart compatibility

Updates since last revision

  • Refactored buildEnvironmentSetup() to use a proper switch statement with assertNever for exhaustiveness checking (addressing review feedback)
  • Added clearer comments explaining that singleBaseUrl environments are generated as enums (not instantiable classes), so they use base_url directly

Testing

  • All python-ast tests pass (156 tests)
  • All python-dynamic-snippets tests pass (29 tests)
  • Manually tested against custom fixture
    • SDK generation completes successfully
    • Generated code passes mypy validation (1830 source files)
    • Wire tests collect successfully (275 tests)

Human Review Checklist

  • Verify switch statement in buildEnvironmentSetup() handles all environment types (null, singleBaseUrl, multipleBaseUrls)
  • Confirm singleBaseUrl environments correctly use base_url directly (since they're enums, not instantiable)
  • Confirm multipleBaseUrls environments correctly instantiate the Environment class with all base URL kwargs

Link to Devin run: https://app.devin.ai/sessions/ff265874ce2541d7b594fc06b67568ae
Requested by: [email protected] (@jsklan)

@github-actions

Copy link
Copy Markdown
Contributor

🌱 Seed Test Selector

Select languages to run seed tests for:

  • Python
  • TypeScript
  • Java
  • Go
  • Ruby
  • C#
  • PHP
  • Swift
  • Rust
  • OpenAPI
  • Postman

How to use: Click the ⋯ menu above → "Edit" → check the boxes you want → click "Update comment". Tests will run automatically and snapshots will be committed to this PR.

@jsklan
jsklan marked this pull request as ready for review December 17, 2025 14:03
Comment on lines +404 to +408
// Fallback to base_url
return {
imports: "",
param: 'base_url="http://localhost:8080"'
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this looks like unreachable code so could probably replace with assertNever(envConfig)

const modulePath = this.getModulePath();
return {
imports: `from ${modulePath}.environment import ${environmentClassName}`,
param: `environment=${environmentClassName}(base="http://localhost:8080")`

@kafkas kafkas Dec 18, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on what I'm seeing, for single base url environments, the environment class we're generating is not an instantiable class but an enum.Enum (e.g. SeedSingleUrlEnvironmentNoDefaultEnvironment.PRODUCTION). In that case do we expect SeedSingleUrlEnvironmentNoDefaultEnvironment(base="http://localhost:8080") to work?

@fern-support
fern-support force-pushed the jsklan/fix-box-python branch from de43c80 to c31f2fc Compare January 7, 2026 20:48
# Conflicts:
#	generators/python-v2/sdk/src/wire-tests/WireTestGenerator.ts
#	generators/python/sdk/versions.yml
@jsklan
jsklan merged commit cb4feb8 into main Jan 8, 2026
@jsklan
jsklan deleted the jsklan/fix-box-python branch January 8, 2026 18:14
kraenhansen added a commit to elevenlabs/elevenlabs-python that referenced this pull request Jul 30, 2026
…819) (#825)

Interim hotfix for the v2.59.0 regression introduced by generator
fern-python-sdk 4.46.9 (commit cb4feb824, PR fern-api/fern#11284), which
began serializing every non-scalar multipart form field via
json.dumps(jsonable_encoder(...)). List[str] fields are not scalar
primitives, so they were sent as a single JSON-array string instead of
repeated form fields -- causing the API to validate the whole array
against per-item limits (e.g. speech_to_text keyterms ->
invalid_keyword_length).

Reverts the 8 list-of-primitive fields to raw values so httpx emits
repeated form fields, matching generator fix 5.22.2. Object fields
(labels, entity_detection, entity_redaction, webhook_metadata) keep
json.dumps. Removes now-unused json / jsonable_encoder imports.

This is intended to be carried across regenerations by Fern Replay and
retired (`fern replay forget`) once the 4.x backport of 5.22.2 lands.

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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.

3 participants