Skip to content

fix(http-client-python): preserve bytes type for raw bytes encoding - #12328

Closed
Hardik K (hardikkaurani) wants to merge 3 commits into
microsoft:mainfrom
hardikkaurani:fix/python-raw-bytes-encoding
Closed

Hardik K (hardikkaurani) wants to merge 3 commits into
microsoft:mainfrom
hardikkaurani:fix/python-raw-bytes-encoding

Conversation

@hardikkaurani

Copy link
Copy Markdown

Fixes #12325

Description

TCGC supplies wireType for encoded bytes. In @typespec/http-client-python, supportedPythonEncodings previously only listed �ase64 and �ase64url for �ytes. Consequently, when raw bytes were annotated with Encode (@encode)("bytes") and TCGC supplied a string wireType, the Python emitter fell back to treating it as an unsupported custom encoding, replacing the client-facing type with string.

This regression caused binary streams (such as XML byte streams) to change from Iterator[bytes] to str, triggering lossy XML scalar deserialization instead of binary streaming.

This PR adds �ytes to supportedPythonEncodings for the �ytes kind, ensuring that raw bytes encoding preserves the �ytes type, maintains binary streaming responses, and prevents fallback to string.

Validation

  • Added focused unit test in packages/http-client-python/emitter/test/types.test.ts
  • Verified unit test passes with 100% success (8/8 passed)
  • Added Chronus change description

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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
@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.

@hardikkaurani

Copy link
Copy Markdown
Author

Hi Yuchao Yan (@msyyc) Timothee Guerin (@timotheeguerin) Vincent Biret (@baywet),

I've opened this PR to resolve issue #12325.

Summary

  • Added �ytes to supportedPythonEncodings for the �ytes type in packages/http-client-python/emitter/src/types.ts.
  • Prevents raw bytes with a wire type from falling back to string, preserving the �ytes type and binary streaming response contracts.
  • Added unit test in packages/http-client-python/emitter/test/types.test.ts verifying that bytes encoded as �ytes preserves { type: "bytes", encode: "bytes" }.
  • Added Chronus change file.

Whenever you have a moment, please take a look. Thank you!

@baywet

Copy link
Copy Markdown
Member

Hardik K (@hardikkaurani) please do not mention me on this repository, I don't have review permissions and it's disruptive.

@hardikkaurani

Copy link
Copy Markdown
Author

Sorry, Vincent Biret (@baywet) I apologize for mentioning you on the microsoft/typespec repository without realizing it would be disruptive. I understand, and I’ll make sure not to mention you on this repository again. Thanks for letting me know.

@l0lawrence

Copy link
Copy Markdown
Member

Hardik K (@hardikkaurani) there is already a pr out to address this, thank you for the contribution. Closing this as a duplicate

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

4 participants