Skip to content

fix(http-client-python): escape wire names in request-builder literals - #12504

Merged
Libba Lawrence (l0lawrence) merged 5 commits into
microsoft:mainfrom
akhil9tiet:fix/12473-wire-name-literals
Nov 6, 2026
Merged

Libba Lawrence (l0lawrence) merged 5 commits into
microsoft:mainfrom
akhil9tiet:fix/12473-wire-name-literals

Conversation

@akhil9tiet

Copy link
Copy Markdown

Fixes #12473

param.wire_name is spliced raw into a single-quoted Python literal in serialize_query_header, so a quote in the wire name closes the literal early and the remainder becomes a live Python expression in the generated module (observed: _params["x" + str(1024) + ""], URL carries computed x1024) or a SyntaxError at import; the fix routes all wire-name interpolations through the existing python_string_literal helper, with regression tests for quotes, backslashes and control characters.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Nov 5, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The delimiter change breaks an existing exact-output unit test, and the user-visible fix is missing the required package changelog entry.

2 open issues
What changed in this PR

This PR addresses #12473 by escaping wire names in Python request builders, preventing specification strings from becoming executable expressions or invalid Python syntax.

Changes:

  • Uses python_string_literal for path keys, query/header keys, and keyword-argument lookups.
  • Adds regression tests verifying that unusual wire names round-trip as literal data.
File Description
packages/​http-client-python/​tests/​unit/​test_string_literals.py Adds literal round-trip tests for query, header, path, and keyword-argument wire names.
packages/​http-client-python/​generator/​pygen/​codegen/​serializers/​parameter_serializer.py Escapes wire names when generating request-builder literals.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The user-visible Python generator fix lacks the required Chronus changelog entry for @typespec/http-client-python, so it would be omitted from the package’s release notes.

1 open issue
1 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the Python request-builder wire-name escaping change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@pkg-pr-new

pkg-pr-new Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-python@12504

commit: bf71080

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @typespec/http-client-python
Show changes

@typespec/http-client-python - fix ✏️

Fix wire names with quotes in generated request-builder code by escaping them through the shared string-literal helper, preserving the existing single-quoted output for popped header/query kwargs.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Python emitter diff

Baseline gh:bb8babf5ca59c9881475e59cdc04c6b288529c4a vs this PR.

No changes to generated output.

Rendered diff: inline on the run summary, or the emitter-diff-html artifact.

Informational check (eng/emitter-diff); does not block the PR.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the Python request-builder wire-name escaping change.

No open issues 🎉

Review effort: Balanced

@l0lawrence
Libba Lawrence (l0lawrence) added this pull request to the merge queue Nov 6, 2026
Merged via the queue into microsoft:main with commit d86f9c5 Nov 6, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:python Issue for the Python client emitter: @typespec/http-client-python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[http-client-python] Query and header parameter wire names are interpolated into generated request builders without escaping

3 participants