Skip to content

fix(python): wrap non-string global header values with str()#15074

Open
patrickthornton wants to merge 3 commits intomainfrom
patrick/python/non-string-headers
Open

fix(python): wrap non-string global header values with str()#15074
patrickthornton wants to merge 3 commits intomainfrom
patrick/python/non-string-headers

Conversation

@patrickthornton
Copy link
Copy Markdown
Contributor

Description

Fixes a mypy failure in the generated Python SDK when an API declares a non-string global header (e.g. Request-Timeout: integer, as used by Vectara).

The generator emits headers: Dict[str, str] but previously assigned the raw typed member directly, producing:

src/vectara/core/client_wrapper.py:46: error: Incompatible types in assignment
    (expression has type "int", target has type "str")  [assignment]
headers["Request-Timeout"] = self._request_timeout

No existing seed fixture declared a non-string global header, so the code path was never exercised.

Changes Made

  • Added is_type_reference_string helper in client_generator/type_utilities.py that unwraps Optional/nullable/alias to detect the underlying primitive.
  • Added a needs_str_conversion flag on ConstructorParameter in core_utilities/client_wrapper_generator.py, set when the header's Fern IR type is not a string.
  • Updated _get_write_get_headers_body to wrap the RHS with str(...) only when needs_str_conversion is True — string-typed headers are emitted unchanged to avoid snapshot churn across existing fixtures.
  • Recorded the fix in generators/python/sdk/versions.yml as 5.4.0-rc.2.

Generated code now produces:

if self._request_timeout is not None:
    headers["Request-Timeout"] = str(self._request_timeout)
  • Updated README.md generator (if applicable)

Testing

Regenerated the Vectara SDK against /Users/Patrick/configs/vectara-fern-config/fern using pnpm seed run --generator python-sdk --skipScripts, then ran the generated project's CI workflow locally:

  • poetry run mypy . — Success: no issues found in 906 source files

  • poetry run pytest -rP -n auto . — 49 passed, 4 skipped

  • poetry install --extras aiohttp && poetry run pytest -rP -n auto -m aiohttp . — 3 passed

  • Unit tests added/updated

  • Manual testing completed

@patrickthornton patrickthornton self-assigned this Apr 15, 2026
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@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

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 15, 2026

SDK Generation Benchmark Results

Comparing PR branch against latest nightly baseline on main (2026-04-15T21:03:37Z).

Full benchmark table (click to expand)
Generator Spec main (generator) main (E2E) PR (generator) Delta
python-sdk square 115s 155s 113s -2s (-1.7%)

main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via fern generate). main (E2E): full customer-observable time including build/test scripts (nightly baseline, informational). Delta is computed against generator-only baseline.
⚠️ = generation exited with a non-zero exit code (timing may not reflect a successful run).
Baseline from nightly runs on main (latest: 2026-04-15T21:03:37Z). Trigger benchmark-baseline to refresh.
Last updated: 2026-04-16 02:10 UTC

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants