You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Python] Model properties with @clientDefaultValue are not included in serialization #10579
When a model has properties with @clientDefaultValue, creating an instance without explicitly setting those properties results in their defaults being excluded from JSON serialization.
Root Cause
PR #10476 changed Model.__init__() to no longer pre-populate _data with field defaults. The _RestField.__get__() was updated to lazily return defaults, but the items() method (used by SdkJSONEncoder for serialization) still only returns self._data.items(), missing the lazily-defaulted fields.
A regression introduced by PR #10476 causes model properties with @clientDefaultValue to be omitted from JSON serialization when not explicitly set, because items() only reads from _data rather than including lazily-defaulted fields.
Category: Bug
Area: emitter:client:python
⚠️ No reproduction provided as a TypeSpec snippet. The issue includes Python-level repro code (not TypeSpec), which is sufficient context for the fix.
🔍 Analysis
Root cause: PR [python] add support for clientDefaultValue to unblock CI #10476 changed Model.__init__() to stop pre-populating _data with defaults, using lazy evaluation in _RestField.__get__() instead. However, items() (used by SdkJSONEncoder) still reads only self._data.items(), so properties that were never explicitly set are invisible to the serializer.
Affected methods: items(), and potentially keys(), values(), __iter__(), __len__(), __contains__()
Impact: Any model using @clientDefaultValue will silently drop those fields from serialization unless the caller explicitly sets them, which can cause incorrect API requests.
📝 Suggested next steps
Update items() (and related iteration methods) in model_base.py.jinja2 to include fields that have lazy defaults but have not been explicitly set in _data
Add or update tests for ModelWithDefaultValues serialization to cover this case
Verify no other serialization paths (e.g., __repr__, as_dict) share the same gap
Activity
skip test_put_model_property pending serialization fix
skip test_put_model_property pending serialization fix
github-actions commentedon Apr 30, 2026
🎯 Issue Triage
A regression introduced by PR #10476 causes model properties with
@clientDefaultValueto be omitted from JSON serialization when not explicitly set, becauseitems()only reads from_datarather than including lazily-defaulted fields.Category: Bug
Area:
emitter:client:python🔍 Analysis
Model.__init__()to stop pre-populating_datawith defaults, using lazy evaluation in_RestField.__get__()instead. However,items()(used bySdkJSONEncoder) still reads onlyself._data.items(), so properties that were never explicitly set are invisible to the serializer.packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2items(), and potentiallykeys(),values(),__iter__(),__len__(),__contains__()@clientDefaultValuewill silently drop those fields from serialization unless the caller explicitly sets them, which can cause incorrect API requests.📝 Suggested next steps
items()(and related iteration methods) inmodel_base.py.jinja2to include fields that have lazy defaults but have not been explicitly set in_dataModelWithDefaultValuesserialization to cover this case__repr__,as_dict) share the same gap