From 92b305d949020bb0684e4374696efc7bf661a3ff Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Tue, 11 Nov 2025 03:42:52 +0000 Subject: [PATCH 1/5] add new section --- doc/dev/mgmt/hybrid_model_migration.md | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/doc/dev/mgmt/hybrid_model_migration.md b/doc/dev/mgmt/hybrid_model_migration.md index d973d49f2d42..aa3284ccfcfb 100644 --- a/doc/dev/mgmt/hybrid_model_migration.md +++ b/doc/dev/mgmt/hybrid_model_migration.md @@ -17,6 +17,7 @@ When migrating to the hybrid model design, expect these breaking changes: | [Additional Properties](#additional-properties-handling) | `additional_properties` parameter removed | Use direct dictionary syntax: `model["key"] = value` | | [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` | | [Serialization/Deserialization](#serialization-and-deserialization-methods-removed) | `serialize` and `deserialize` methods removed | Use dictionary access for serialization, constructor for deserialization | +| [Reserved Property Names](#reserved-property-name-conflicts) | Conflicting names suffixed with `_property` | Change code to use renamed property | ## Detailed Breaking Changes @@ -273,6 +274,50 @@ serialized_dict = as_attribute_dict(model, exclude_readonly=False) serialized_dict = as_attribute_dict(model, exclude_readonly=True) ``` +### Reserved Property Name Conflicts + +**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. + +**What will break**: + +- Constructor calls that pass reserved names as keyword arguments: `Model(keys=...)` now raises or binds incorrectly. +- Attribute access expecting the property value: `model.keys` now refers to the method; calling it without parentheses will not return the property data. + +**Before**: + +```python +from azure.mgmt.test.models import Model + +model = Model(keys={"a": 1}, values=[1, 2, 3]) +print(model.keys) # Property value (old behavior) +print(model.values) # Property value (old behavior) +print(model.as_dict()["keys"]) # REST layer value +``` + +**After**: + +```python +from azure.mgmt.test.models import Model + +# Reserved property names receive a `_property` suffix +model = Model(keys_property={"a": 1}, values_property=[1, 2, 3]) + +print(model.keys_property) # ✅ Property value +print(model.values_property) # ✅ Property value +print(model["keys"]) # REST layer value + +# Unsuffixed names are now dict methods +print(list(model.keys())) # ✅ Dict method listing all serialized keys in the model +print(list(model.values())) # ✅ Dict method listing all values +``` + +**Migration steps:** + +1. Search for any usage of reserved names as constructor keywords or attribute accesses. +2. Append `_property` to both initialization and attribute access: `Model(keys=...)` → `Model(keys_property=...)`; `model.keys` → `model.keys_property`. +3. Update tests and documentation references accordingly. +4. If you had dynamic code relying on `getattr(model, name)`, ensure you add a rule to transform reserved names to `name + "_property"` first. + --- ## Additional Helper Methods From 8b722d772fcc05be4a5b45ed65285d7e13a8ef8d Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Tue, 11 Nov 2025 13:37:48 +0800 Subject: [PATCH 2/5] Update doc/dev/mgmt/hybrid_model_migration.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- doc/dev/mgmt/hybrid_model_migration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/mgmt/hybrid_model_migration.md b/doc/dev/mgmt/hybrid_model_migration.md index aa3284ccfcfb..6ebba3c9da51 100644 --- a/doc/dev/mgmt/hybrid_model_migration.md +++ b/doc/dev/mgmt/hybrid_model_migration.md @@ -17,7 +17,7 @@ When migrating to the hybrid model design, expect these breaking changes: | [Additional Properties](#additional-properties-handling) | `additional_properties` parameter removed | Use direct dictionary syntax: `model["key"] = value` | | [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` | | [Serialization/Deserialization](#serialization-and-deserialization-methods-removed) | `serialize` and `deserialize` methods removed | Use dictionary access for serialization, constructor for deserialization | -| [Reserved Property Names](#reserved-property-name-conflicts) | Conflicting names suffixed with `_property` | Change code to use renamed property | +| [Reserved Property Names](#reserved-property-name-conflicts) | Conflicting names suffixed with `_property` | Update code to use `_property` suffix: `model.keys` → `model.keys_property` | ## Detailed Breaking Changes From eccb9453e3dc871a4844d1f77805e53734d672c0 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Tue, 11 Nov 2025 13:38:02 +0800 Subject: [PATCH 3/5] Update doc/dev/mgmt/hybrid_model_migration.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- doc/dev/mgmt/hybrid_model_migration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/mgmt/hybrid_model_migration.md b/doc/dev/mgmt/hybrid_model_migration.md index 6ebba3c9da51..2d88981db77f 100644 --- a/doc/dev/mgmt/hybrid_model_migration.md +++ b/doc/dev/mgmt/hybrid_model_migration.md @@ -307,7 +307,7 @@ print(model.values_property) # ✅ Property value print(model["keys"]) # REST layer value # Unsuffixed names are now dict methods -print(list(model.keys())) # ✅ Dict method listing all serialized keys in the model +print(list(model.keys())) # ✅ Dict method listing all keys in the model print(list(model.values())) # ✅ Dict method listing all values ``` From 159a5bee04bd0b08b394fc452c0dfed4b18b60a1 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Tue, 11 Nov 2025 13:38:48 +0800 Subject: [PATCH 4/5] Update doc/dev/mgmt/hybrid_model_migration.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- doc/dev/mgmt/hybrid_model_migration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/mgmt/hybrid_model_migration.md b/doc/dev/mgmt/hybrid_model_migration.md index 2d88981db77f..76cea7b9eeb6 100644 --- a/doc/dev/mgmt/hybrid_model_migration.md +++ b/doc/dev/mgmt/hybrid_model_migration.md @@ -280,7 +280,7 @@ serialized_dict = as_attribute_dict(model, exclude_readonly=True) **What will break**: -- Constructor calls that pass reserved names as keyword arguments: `Model(keys=...)` now raises or binds incorrectly. +- 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. - Attribute access expecting the property value: `model.keys` now refers to the method; calling it without parentheses will not return the property data. **Before**: From 9d327c839cea85fae2ac8121a06d5ef30d663230 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Wed, 12 Nov 2025 10:57:29 +0800 Subject: [PATCH 5/5] Update hybrid_model_migration.md --- doc/dev/mgmt/hybrid_model_migration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/mgmt/hybrid_model_migration.md b/doc/dev/mgmt/hybrid_model_migration.md index 76cea7b9eeb6..9e63c63b476d 100644 --- a/doc/dev/mgmt/hybrid_model_migration.md +++ b/doc/dev/mgmt/hybrid_model_migration.md @@ -306,7 +306,7 @@ print(model.keys_property) # ✅ Property value print(model.values_property) # ✅ Property value print(model["keys"]) # REST layer value -# Unsuffixed names are now dict methods +# names without suffix are now dict methods print(list(model.keys())) # ✅ Dict method listing all keys in the model print(list(model.values())) # ✅ Dict method listing all values ```