Fix Python raw XML byte-stream regression for legacy bytes encoding by Copilot · Pull Request #12326 · microsoft/typespec · GitHub
Skip to content

Fix Python raw XML byte-stream regression for legacy bytes encoding - #12326

Merged
iscai-msft merged 5 commits into
mainfrom
copilot/fix-python-emitter-xml-bug
Oct 21, 2026
Merged

iscai-msft merged 5 commits into
mainfrom
copilot/fix-python-emitter-xml-bug

Conversation

Copilot AI commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

New TCGC wireType metadata caused legacy @encode("bytes") XML responses to become str instead of byte iterators. XML scalar deserialization then discarded child elements and attributes.

  • Compatibility: Recognize "bytes" as a supported bytes encoding, preserving sync Iterator[bytes], async AsyncIterator[bytes], and default streaming. Genuinely unsupported/custom encodings retain the wire-type fallback.
  • Regression coverage: Cover encoded-bytes metadata, real TypeSpec XML emission, generated sync/async signatures, and byte-for-byte preservation of compact and pretty-printed publishing-profile XML.

@azure-pipelines

Copy link
Copy Markdown

Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
@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 Oct 21, 2026
Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Python emitter change causing XML content loss Fix Python raw XML byte-stream regression for legacy bytes encoding Oct 21, 2026
@msyyc
Yuchao Yan (msyyc) requested a balanced review from Copilot October 21, 2026 08:37

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

The narrow compatibility fix preserves custom-encoding fallback and includes targeted regression coverage, with no blocking issues identified.

No open issues 🎉

What changed in this PR

Restores Python’s legacy raw-byte XML response contract, addressing the compatibility regression described in #12325.

Changes:

  • Recognizes "bytes" encoding while preserving fallback for unsupported encodings.
  • Adds emitter and Python regression coverage for sync/async streaming and complete XML preservation.
  • Documents the fix in a changelog entry.
File Description
packages/​http-client-python/​tests/​unit/​test_raw_bytes_xml.py Tests signatures, default streaming, and XML preservation.
packages/​http-client-python/​emitter/​test/​types.test.ts Covers legacy bytes encoding and custom-encoding fallback.
packages/​http-client-python/​emitter/​test/​test-host.ts Registers the HTTP library for tests.
packages/​http-client-python/​emitter/​test/​emitter.test.ts Tests emission from a legacy XML response specification.
packages/​http-client-python/​emitter/​src/​types.ts Adds "bytes" to supported bytes encodings.
.chronus/​changes/​copilot-fix-python-emitter-xml-bug-2026-9-21-8-26-3.md Records the compatibility fix.

Review effort: Balanced

@pkg-pr-new

pkg-pr-new Bot commented Oct 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 36fcfd3

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

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

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

Preserve raw byte streaming for XML responses using the legacy bytes encoding instead of deserializing them as XML string scalars.

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

The narrow compatibility fix has focused regression coverage and no identified blocking issues; tests were not executed during review.

No open issues 🎉

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Python emitter diff

Baseline gh:e4f588a5fe8765179ca0d7dea0f73e51c5b79950 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.

@azure-sdk-automation

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@iscai-msft
iscai-msft added this pull request to the merge queue Oct 21, 2026
Merged via the queue into main with commit c114161 Oct 21, 2026
38 checks passed
@iscai-msft
iscai-msft deleted the copilot/fix-python-emitter-xml-bug branch October 21, 2026 20:54
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.

[Bug]: Python emitter changes raw XML byte streams to str and loses publishing-profile content after upgrade

5 participants