Skip to content

[python] Fix @clientDefaultValue serialization regression from #10476#10546

Open
Copilot wants to merge 4 commits intomainfrom
copilot/fix-issue-with-typespec
Open

[python] Fix @clientDefaultValue serialization regression from #10476#10546
Copilot wants to merge 4 commits intomainfrom
copilot/fix-issue-with-typespec

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 29, 2026

Follow-up to #10476 addressing review comment r3160211783.

#10476 stopped pre-populating Model._data with @clientDefaultValue defaults in __init__ and instead added a fallback in _RestField.__get__. That fallback only covers Python attribute reads — serialization goes through dict(model.items()), which iterates _data, so client defaults were silently dropped from request bodies.

Repro against azure-client-generator-core/client-default-value:

body = ModelWithDefaultValues(name="test")
client.put_model_property(body=body)
# Sent:     {"name": "test"}
# Expected: {"name": "test", "timeout": 30, "tier": "standard", "retry": true}

Changes

  • generator/pygen/codegen/templates/model_base.py.jinja2: After dict_to_pass is populated from args/kwargs in Model.__init__, fill in _default for any rest field the caller didn't provide. Restores pre-[python] add support for clientDefaultValue to unblock CI #10476 wire behavior while keeping the new _RestField.__get__ fallback as a safety net for unset fields without a default.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 6, 2026

Open in StackBlitz

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

commit: a477100

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

All changed packages have been documented.

  • @typespec/http-client-python
Show changes

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

Fix serialization regression where @clientDefaultValue defaults on model properties were no longer included in the request body. Defaults are again materialized in the model's data dictionary at construction time so they are sent on the wire, while the attribute-access fallback for unset fields is preserved.

@azure-sdk
Copy link
Copy Markdown
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

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 eng

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants