Skip to content

[python] support custom wire names for etags defined with Azure.Core.eTag#10494

Open
iscai-msft wants to merge 6 commits intomicrosoft:mainfrom
iscai-msft:python/etagMatchCondition
Open

[python] support custom wire names for etags defined with Azure.Core.eTag#10494
iscai-msft wants to merge 6 commits intomicrosoft:mainfrom
iscai-msft:python/etagMatchCondition

Conversation

@iscai-msft
Copy link
Copy Markdown
Member

Problem

Custom etag-typed headers (e.g. x-ms-if-blob-match, x-ms-if-blob-none-match) were being assigned to the wrong if-match/if-none-match slot during preprocessing. The slot assignment and the per-parameter conversion used different logic to classify headers, and synthetic partners inherited incorrect wire names.

Changes

  • Added _etag_kind() helper — centralizes etag classification using none-match substring (stricter than the previous none check which could false-positive on unrelated headers)
  • Fixed slot assignment — uses _etag_kind() to correctly classify custom etag headers before pairing
  • Fixed synthetic partner creation — strips isEtag from synthetic clones to prevent re-conversion with wrong originalWireName, falls back to standard If-Match/If-None-Match wire names
  • Unified classification — both slot assignment and per-parameter conversion now use the same _etag_kind() logic

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 24, 2026

Open in StackBlitz

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

commit: e327a0d

@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 Apr 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

All changed packages have been documented.

  • @typespec/http-client-python
Show changes

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

Support custom wire names for etags defined with Azure.Core.eTag (e.g. x-ms-blob-if-match)

@azure-sdk
Copy link
Copy Markdown
Collaborator

azure-sdk commented Apr 24, 2026

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes how the Python HTTP client generator handles custom ETag-typed header parameters (e.g. x-ms-if-blob-match, x-ms-if-blob-none-match) by centralizing ETag header classification and ensuring serialization uses the real HTTP header name.

Changes:

  • Add a shared _etag_kind() helper to consistently classify ETag headers as if-match vs if-none-match.
  • Preserve the actual header name via originalWireName during preprocessing and use it during header serialization.
  • Emit an isEtag flag from the TypeScript emitter so preprocessing can detect custom ETag-typed headers.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/http-client-python/generator/pygen/preprocess/init.py Centralizes ETag header classification, fixes slot pairing, and preserves originalWireName during header conversion.
packages/http-client-python/generator/pygen/codegen/serializers/parameter_serializer.py Builds ETag header serialization using original_wire_name instead of hard-coded If-Match/If-None-Match.
packages/http-client-python/generator/pygen/codegen/models/parameter.py Adds original_wire_name field to parameter model for downstream serialization.
packages/http-client-python/emitter/src/http.ts Emits isEtag for header parameters by detecting Azure.Core.eTag scalar types.
.chronus/changes/python-etagMatchCondition-2026-04-24-18-22-00.md Changelog entry documenting the fix.

Comment thread packages/http-client-python/generator/pygen/preprocess/__init__.py Outdated
Comment thread packages/http-client-python/generator/pygen/preprocess/__init__.py Outdated
Custom headers typed as Azure.Core.eTag (e.g. x-ms-blob-if-match,
x-ms-source-if-match) now get the same etag/match_condition treatment
as standard If-Match/If-None-Match headers. The original wire name is
preserved via originalWireName so the correct HTTP header is sent.

- Add isEtag flag in emitter for Azure.Core.eTag-typed headers
- Add _is_etag_match/_is_etag_none_match helpers in preprocessor
- Preserve originalWireName in headers_convert for custom headers
- Use originalWireName in serializer for dynamic header name
- Use identity-based removal for etag param reordering

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@iscai-msft iscai-msft force-pushed the python/etagMatchCondition branch from 15ed29c to f9b7c14 Compare April 27, 2026 17:33
iscai-msft and others added 3 commits April 27, 2026 14:10
Move etagRole determination into the emitter's getEtagRole() function.
Standard If-Match/If-None-Match headers work with any type.
Non-standard headers (e.g. x-ms-blob-if-match) require Azure.Core.eTag type.
Simplify preprocess _get_etag_role to just read the etagRole field.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@iscai-msft iscai-msft changed the title fix(http-client-python): correct etag slot assignment for custom etag-typed headers [python] support custom wire names for etags defined with Azure.Core.eTag Apr 27, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@msyyc msyyc left a comment

Choose a reason for hiding this comment

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

Overall looks good to me. Maybe we could ask TCGC to provide a helper function to help judge etag type in the future.

@msyyc msyyc self-requested a review April 28, 2026 03:32
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.

4 participants