Skip to content

Commit 2c633db

Browse files
msyycCopilot
andauthored
[doc] add new section for hybrid model migration (#43933)
* add new section * Update doc/dev/mgmt/hybrid_model_migration.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update doc/dev/mgmt/hybrid_model_migration.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update doc/dev/mgmt/hybrid_model_migration.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update hybrid_model_migration.md --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 6bfd630 commit 2c633db

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

doc/dev/mgmt/hybrid_model_migration.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ When migrating to the hybrid model design, expect these breaking changes:
1717
| [Additional Properties](#additional-properties-handling) | `additional_properties` parameter removed | Use direct dictionary syntax: `model["key"] = value` |
1818
| [String Representation](#string-representation-matches-rest-api) | Model key output changed from `snake_case` to `camelCase` | Update any code parsing model strings to expect `camelCase` |
1919
| [Serialization/Deserialization](#serialization-and-deserialization-methods-removed) | `serialize` and `deserialize` methods removed | Use dictionary access for serialization, constructor for deserialization |
20+
| [Reserved Property Names](#reserved-property-name-conflicts) | Conflicting names suffixed with `_property` | Update code to use `_property` suffix: `model.keys``model.keys_property` |
2021

2122
## Detailed Breaking Changes
2223

@@ -273,6 +274,50 @@ serialized_dict = as_attribute_dict(model, exclude_readonly=False)
273274
serialized_dict = as_attribute_dict(model, exclude_readonly=True)
274275
```
275276

277+
### Reserved Property Name Conflicts
278+
279+
**What changed**: Hybrid models now inherit from Python's built-in `dict`. If a REST API property name collides with a `dict` method name (e.g. `keys`, `values`, `items`, `clear`, `update`, `get`, `pop`, `popitem`, `setdefault`, `copy`), the Python emitter appends `_property` to the generated attribute to avoid masking the dictionary method.
280+
281+
**What will break**:
282+
283+
- Constructor calls that pass reserved names as keyword arguments: `Model(keys=...)` will now pass the argument to the underlying `dict` constructor, which means the property value will not be set as expected and may result in a `TypeError` or unexpected behavior.
284+
- Attribute access expecting the property value: `model.keys` now refers to the method; calling it without parentheses will not return the property data.
285+
286+
**Before**:
287+
288+
```python
289+
from azure.mgmt.test.models import Model
290+
291+
model = Model(keys={"a": 1}, values=[1, 2, 3])
292+
print(model.keys) # Property value (old behavior)
293+
print(model.values) # Property value (old behavior)
294+
print(model.as_dict()["keys"]) # REST layer value
295+
```
296+
297+
**After**:
298+
299+
```python
300+
from azure.mgmt.test.models import Model
301+
302+
# Reserved property names receive a `_property` suffix
303+
model = Model(keys_property={"a": 1}, values_property=[1, 2, 3])
304+
305+
print(model.keys_property) # ✅ Property value
306+
print(model.values_property) # ✅ Property value
307+
print(model["keys"]) # REST layer value
308+
309+
# names without suffix are now dict methods
310+
print(list(model.keys())) # ✅ Dict method listing all keys in the model
311+
print(list(model.values())) # ✅ Dict method listing all values
312+
```
313+
314+
**Migration steps:**
315+
316+
1. Search for any usage of reserved names as constructor keywords or attribute accesses.
317+
2. Append `_property` to both initialization and attribute access: `Model(keys=...)``Model(keys_property=...)`; `model.keys``model.keys_property`.
318+
3. Update tests and documentation references accordingly.
319+
4. If you had dynamic code relying on `getattr(model, name)`, ensure you add a rule to transform reserved names to `name + "_property"` first.
320+
276321
---
277322

278323
## Additional Helper Methods

0 commit comments

Comments
 (0)