Repository navigation
Description
Describe the bug
The Python sample serializer appears to emit invalid Python when an If-Match example contains a quoted ETag.
Python SDK validation for Azure/azure-rest-api-specs-pr#31004, build 7038958, reports Black UnterminatedString errors in four generated Boundary samples: AddBinding, Delete, RemoveBinding, and UpdateBindingParameters. These operations require an If-Match header with quoted ETag example values.
Reproduction
A matching failure was reported using the published @typespec/http-client-python 0.39.0 sample serializer.
For this JSON example parameter:
"If-Match": "\"1\""The actual header value is the three-character string "1", including both quotation marks. SampleSerializer.handle_param reportedly generates:
if_match=""""1"""",This is invalid Python and fails parsing/Black.
Expected output, or an equivalent valid Python string literal:
if_match='"1"',The value passed to the SDK must retain the quotation marks, so the HTTP request sends:
If-Match: "1"Quoted strong entity tags are valid HTTP If-Match values: RFC 9110, section 13.1.1.
Investigation and possible fix
A reported scratch experiment using repr(param_value) for string-literal serialization preserved the exact header value and passed parsing/Black for all four affected inputs. This is a candidate fix, not a confirmed supported workaround or an upstream fix.
Please investigate Python string-literal escaping in the sample serializer and add regression coverage for quoted ETags. The fix must preserve the required header and the exact ETag value; removing the header, stripping its quotes, or replacing it with * would change the API semantics.
Version and confirmation needed
- Reproduction version reported:
@typespec/http-client-python0.39.0. - The exact emitter version installed in failed CI build 7038958 is not yet confirmed.
- Please confirm whether an existing issue/fix covers this behavior and identify the first corrected emitter version, or a supported fix if no release contains it.
Related report
- https://github.com/Azure/azure-rest-api-specs-pr/pull/31004 (access may be restricted).
- Affected example reported:
Boundary_AddBinding.json; the same failure is reported for Delete, RemoveBinding, and UpdateBindingParameters.
Additional source confirmation
The current mainline SampleSerializer.handle_param was independently inspected while filing this issue. It uses this branch for strings containing a carriage return, newline, or double quote:
if isinstance(param_value, str):
if any(i in param_value for i in '\r\n"'):
return f'"""{param_value}"""'This confirms the problematic literal construction remains in the current source. It does not establish which emitter version the failed CI build installed or identify a corrected release.
Reported failing check: SDK Validation - Python - PR, build 7038958.
Activity
github-actions commentedon Nov 5, 2026
🎯 Issue Triage
The Python client emitter's sample serializer produces an invalid triple-quoted literal when a string parameter contains quotation marks, breaking generated Boundary samples during parsing and Black formatting. The quoted ETag value must be preserved exactly for the
If-Matchheader.Category: Bug
Area:
emitter:client:python🔍 Analysis
SampleSerializer.handle_paramwraps any string containing\r,\n, or"in triple double quotes without escaping embedded delimiters. For the value"1", the surrounding and embedded quotes form an invalid Python token sequence. This affects generated samples from@typespec/http-client-python; using a Python literal-escaping mechanism such asreprappears directionally appropriate but should be validated for multiline strings, backslashes, quotes, and exact value preservation.No strong duplicate was found. #10784 and #11881 concern Python docstring escaping, whereas this issue affects serialization of runtime sample parameter values.
📝 Suggested next steps
If-MatchETag.