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
[Bug]: [python] Reading a model property detaches the container previously returned by __getitem__, dropping mutations #12360
In the Python emitter's generated model runtime (_utils/model_base.py, from packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2), _RestField.__get__ deserializes list, dict and set values. It then stores the new container back into obj._data[rest_name] and sets _deserialized_<rest_name>.
Any container a caller got earlier through mapping access (obj["rest_name"]) is now detached from the model, so later mutations through that reference are silently dropped from as_dict() and request serialization. No error is raised.
The problem is limited to mixing dict access and property access on the same field. Mutating through a property reference (model.field.append(...)) works correctly; the property caching fixed that, since older generated runtimes lost those mutations. The remaining gap is the dict-then-property order:
Access order
Mutation kept?
dict → property → mutate dict ref
❌ lost
property → dict → mutate property ref
✅
property → mutate
✅
dict → mutate
✅
property → property → mutate first ref
✅
Lists of models aren't affected: their deserializer returns the original list. Lists and dicts of primitives (for example list[str], dict[str, str]) are affected.
Expected: mapping access and property access share one backing container, so a mutation through either reference serializes.
Reproduction
Failing unit tests: #12359 (adds to packages/http-client-python/tests/unit/test_model_base_serialization.py). 2 new tests fail, the guard and existing tests pass:
🎯 Issue Triage
The generated Python model runtime can replace a list or dictionary during property deserialization, detaching a container reference previously returned by mapping access and silently omitting later mutations from serialization.
Category: Bug Area: emitter:client:python
⚠️ No TypeSpec playground reproduction is applicable. The issue provides a minimal Python runtime reproduction and focused failing tests in #12359.
🔍 Analysis
The affected component is packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2, specifically _RestField.__get__. The likely cause is that deserialization of primitive lists, dictionaries, and sets creates and caches a new container in obj._data, while an earlier obj[rest_name] reference still points to the original container. Lists of models are reportedly unaffected because their deserializer preserves the original list identity.
Focused searches found no existing issue describing the same access-order-dependent container detachment.
📝 Suggested next steps
Preserve container identity when caching deserialized list, dictionary, and set values, or otherwise keep mapping and property access synchronized.
Activity
github-actions commentedon Oct 22, 2026
🎯 Issue Triage
The generated Python model runtime can replace a list or dictionary during property deserialization, detaching a container reference previously returned by mapping access and silently omitting later mutations from serialization.
Category: Bug
Area:
emitter:client:python🔍 Analysis
The affected component is
packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2, specifically_RestField.__get__. The likely cause is that deserialization of primitive lists, dictionaries, and sets creates and caches a new container inobj._data, while an earlierobj[rest_name]reference still points to the original container. Lists of models are reportedly unaffected because their deserializer preserves the original list identity.Focused searches found no existing issue describing the same access-order-dependent container detachment.
📝 Suggested next steps
as_dict()for both access orders.