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
Copy file name to clipboardExpand all lines: doc/dev/mgmt/hybrid_model_migration.md
+45Lines changed: 45 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,7 @@ When migrating to the hybrid model design, expect these breaking changes:
17
17
|[Additional Properties](#additional-properties-handling)|`additional_properties` parameter removed | Use direct dictionary syntax: `model["key"] = value`|
18
18
|[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`|
19
19
|[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`|
**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.
0 commit comments