Skip to content

fix(python): Fix boolean path parameters serialized as True/False instead of true/false#14789

Merged
jsklan merged 4 commits intomainfrom
devin/1775695540-fix-python-sdk-boolean-path-params
Apr 9, 2026
Merged

fix(python): Fix boolean path parameters serialized as True/False instead of true/false#14789
jsklan merged 4 commits intomainfrom
devin/1775695540-fix-python-sdk-boolean-path-params

Conversation

@jsklan
Copy link
Copy Markdown
Contributor

@jsklan jsklan commented Apr 9, 2026

Description

Fix boolean path parameters in the Python SDK being serialized as Python-style True/False instead of JSON-style true/false in URL paths. This causes WireMock test failures and incorrect API calls when boolean values appear in path segments.

Root cause: The generator used jsonable_encoder() for path parameter interpolation. Since bool is a subclass of int in Python, jsonable_encoder returns booleans as-is, and Python's default str() produces True/False when interpolated into f-strings.

Changes Made

  • Added encode_path_param() utility function in jsonable_encoder.py that explicitly handles booleans with lowercase true/false, and delegates to jsonable_encoder + str() for all other types
  • Registered encode_path_param as an exported core utility in core_utilities.py
  • Updated endpoint_function_generator.py to use encode_path_param instead of jsonable_encoder for path parameter interpolation
  • Updated websocket_connect_method_generator.py to also use encode_path_param (same pattern as endpoint generator — flagged by Devin Review)
  • Added getWithBooleanPath endpoint to the exhaustive test fixture to cover boolean path parameters
  • Updated IR snapshot files for the exhaustive fixture (both ir and dynamic-snippets)
  • Version bump to 5.3.4 with changelog entry

Important Review Notes

  • The str(jsonable_encoder(obj)) fallback in encode_path_param mirrors the existing implicit stringification that happens when values are interpolated into f-strings, so non-boolean types should behave identically to before.
  • ⚠️ Seed snapshot files: The seed-test-results (python-sdk) CI check passes (generated code compiles and tests pass), but the actual seed snapshot files under seed/python-sdk/exhaustive/ have not been committed in this PR. A reviewer may want to run pnpm seed:local test --generator python-sdk --fixture exhaustive locally and commit the updated snapshots, or confirm CI's passing result is sufficient.
  • The test-ete CI check failure is unrelated — it's a timeout in generate-with-settings.test.ts > dependencies-based api and is not marked as required.

Testing

  • Pre-commit hooks pass (poetry run pre-commit run -a)
  • pnpm format passes
  • IR snapshot tests updated and passing locally
  • All required CI checks passing (test, compile, lint, seed-test-results, etc.)
  • Reproduced the bug locally via pnpm seed:local run --generator python-sdk --path <customer-api-path> — confirmed WireMock error: Path parameter: ignoreEmpty = true | True <<<<< Path parameter does not match

For reviewer

  • Are there other code paths beyond endpoint_function_generator.py and websocket_connect_method_generator.py that interpolate path parameters and may need the same fix?
  • Verify encode_path_param handles edge cases (e.g., None, enums, nested types) — the str(jsonable_encoder(obj)) fallback should cover these, but worth confirming
  • Decide whether seed snapshot files under seed/python-sdk/exhaustive/ need to be committed (CI seed tests pass without them)

Link to Devin session: https://app.devin.ai/sessions/25a25e3ba67447f59aa5d11486e44726
Requested by: @jsklan


Open with Devin

devin-ai-integration bot and others added 2 commits April 9, 2026 01:30
Co-Authored-By: judah <jsklan.development@gmail.com>
…erator

Co-Authored-By: judah <jsklan.development@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@devin-ai-integration devin-ai-integration bot changed the title fix(python-sdk): Fix boolean path parameters serialized as True/False instead of true/false fix(python): Fix boolean path parameters serialized as True/False instead of true/false Apr 9, 2026
Co-Authored-By: judah <jsklan.development@gmail.com>
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

🐛 1 issue in files not directly in the diff

🐛 Websocket path parameters not updated to use encode_path_param (generators/python/src/fern_python/generators/sdk/client_generator/websocket_connect_method_generator.py:542)

The PR's fix for boolean path parameter encoding was applied to endpoint_function_generator.py (line 1019) but the identical pattern in websocket_connect_method_generator.py:542 still uses jsonable_encoder. This means websocket endpoints with boolean path parameters will still serialize as Python-style True/False instead of lowercase true/false. The two methods (_get_path_for_endpoint and _get_path_for_websocket) are structurally identical, and the transformation was only applied to one of them.

View 2 additional findings in Devin Review.

Open in Devin Review

Co-Authored-By: judah <jsklan.development@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor

Addressed the Devin Review finding — updated websocket_connect_method_generator.py to also use encode_path_param instead of jsonable_encoder for path parameter interpolation (commit 9f6894f).

@jsklan jsklan marked this pull request as ready for review April 9, 2026 04:24
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

github-actions bot commented Apr 9, 2026

SDK Generation Benchmark Results

Comparing PR branch against latest nightly baseline on main (2026-04-08T04:49:09Z).

Full benchmark table (click to expand)
Generator Spec main (generator) main (E2E) PR (generator) Delta
csharp-sdk square 132s 171s 91s -41s (-31.1%)
go-sdk square 280s 345s 105s -175s (-62.5%)
java-sdk square 311s 371s 273s -38s (-12.2%)
php-sdk square 127s 155s 85s -42s (-33.1%)
python-sdk square 168s 204s 124s -44s (-26.2%)
ruby-sdk-v2 square 152s 192s 112s -40s (-26.3%)
rust-sdk square 137s 127s 94s -43s (-31.4%)
swift-sdk square 141s 486s 102s -39s (-27.7%)
ts-sdk square 142s 173s 108s -34s (-23.9%)

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-08T04:49:09Z). Trigger benchmark-baseline to refresh.

@jsklan jsklan merged commit 4938db4 into main Apr 9, 2026
180 of 182 checks passed
@jsklan jsklan deleted the devin/1775695540-fix-python-sdk-boolean-path-params branch April 9, 2026 13:03
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