Skip to content

[Bug]: Python sample generation loses REST body example values when the SDK parameter is renamed #12433

Open

Description

@Y-Sindo

[Bug]: Python sample generation loses REST body example values when the SDK parameter is renamed

Describe the bug

With @typespec/http-client-python 0.38.1, applying a client-only name to an explicitly named request body causes generated Python samples to use placeholder values instead of the values from the REST example.

The SDK parameter rename itself is correct. The problem is that sample generation looks up the original REST example using the renamed SDK parameter name.

Reproduction

Observed while generating the Web PubSub Chat Python SDK from:

  • TypeSpec source PR
  • Reproduced source revision: cac305c7810afd20b8cfa009852d4fb0975c528a
  • TypeSpec project: specification/webpubsub/data-plane/WebPubSubChat
  • Python emitter: @typespec/http-client-python 0.38.1
  • TCGC: @azure-tools/typespec-client-generator-core 0.73.0
  • Python SDK PR

The source PR uses a scoped $clientName customization on the instantiated request body parameter of createOrReplaceTopic, changing its SDK name from resource to topic without changing the REST example.

  1. Generate the Python SDK and samples from the source above using the Python emitter.
  2. Inspect the generated sync and async samples for create_or_replace_topic.
  3. Compare their request body values with the REST example, whose relevant fragment is:
{
  "parameters": {
    "resource": {
      "title": "Product updates",
      "state": "Normal"
    }
  }
}

Expected behavior

The Python parameter should be named topic, while the generated sample retains the example's actual values:

topic={"title": "Product updates", "state": "Normal"}

Actual behavior

The generated sample uses fallback values:

topic={"title": "str", "state": "str"}

An existing SDK regression test checking the topic example fails after regeneration. This report concerns generated sample content; it does not establish a runtime request serialization failure.

Investigation

Inspecting TCGC's SDK context for the affected operation shows:

body.name = "topic"
body.serializedName = "resource"
body.__raw.name = "resource"

TCGC retains the correct example association and values in operation.examples.parameters; the raw example also retains parameters.resource. The example values are therefore still available before conversion to the Python generator's intermediate representation.

In emitHttpBodyParameter, the body parameter is emitted with:

clientName: bodyParam.isGeneratedName ? "body" : getClientName(bodyParam),
wireName: bodyParam.isGeneratedName ? "body" : bodyParam.name,

In sample_serializer.py, the example lookup uses:

param_value = self.sample_params.get(param.wire_name)

Consequently, the lookup uses topic against a REST example keyed by resource, and sample generation falls back to synthetic values.

These code paths are also present on the repository's current main. Reproduction was performed with version 0.38.1; the current main version has not been executed to reproduce the issue.

Suggested fix and regression coverage

Please consider preserving bodyParam.serializedName as the lookup identity for explicitly named request bodies, while retaining the renamed SDK clientName and the existing handling of generated body names.

A regression case should cover a request body renamed only for the SDK, a REST example still keyed by its original name, and generated sync/async samples retaining the original example values.

Changing the REST examples to use SDK-only names would not preserve the intended separation between the REST contract and SDK customization.

Activity

  1. added
    bug
    on Oct 29, 2026
  2. added
    emitter:client:python
    on Oct 29, 2026
  3. github-actions commented on Oct 29, 2026

    @github-actions
    Contributor

    🎯 Issue Triage
    Python sample generation loses REST example values when an explicitly named request body receives an SDK-only rename.
    The emitted parameter name is correct, but example lookup uses that client name instead of the original serialized name and falls back to placeholders.
    Category: Bug
    Area: emitter:client:python

    ⚠️ No reproduction provided. A minimal repro would help diagnose this issue.

    🔍 Analysis

    The affected path is the Python client emitter's sample generation. TCGC retains both the renamed SDK name (topic) and serialized REST name (resource), but emitHttpBodyParameter appears to populate wireName from bodyParam.name; sample_serializer.py then indexes the REST example by that value. This causes a miss against parameters.resource and synthetic sample values are generated.

    The report includes concrete source and generated-SDK revisions, but no inline TypeSpec reproduction suitable for a playground link. #9137 is related to client-name/wire-name separation in multipart serialization, but it describes a different runtime serialization path and is not a duplicate.

    📝 Suggested next steps
    • Add a minimal Python emitter regression fixture with an SDK-only request-body rename and a REST example keyed by the serialized name.
    • Verify generated synchronous and asynchronous samples preserve the example values.
    • Use the serialized body name for example lookup while preserving the renamed client-facing parameter.

    Generated by Agentic Triage

  4. akhil9tiet commented on Oct 29, 2026

    @akhil9tiet

    I'd like to work on this — please assign it to me.

  5. lmazuel commented on Oct 30, 2026

    @lmazuel
    Member

    Hey Akhil Gupta (@akhil9tiet) , I can't assign the issue per say to you, but you're welcome to open a PR and we will review it. Thank you for your contributions!

  6. binnguyenx commented on Nov 30, 2026

    @binnguyenx
    Contributor

    Hi Akhil Gupta (@akhil9tiet), I didn't see a PR from you for this, so I opened #12688 with a fix (it uses the body's serializedName as its wire name, so samples find the REST example values again). If you already have work in progress, let me know and I'm happy to close mine or help review yours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugemitter:client:python

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions