[core] add tests and fix backcompat functions#44084
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive test coverage and fixes the backward compatibility functions attribute_list and as_attribute_dict to handle properties that are padded in TypeSpec-generated code but were not padded in AutoRest-generated code. The fix introduces an original_tsp_name parameter to track the original property names before padding, ensuring backward compatibility with existing code.
Key Changes:
- Added
original_tsp_nameparameter to_RestFieldandrest_fieldto track original TypeSpec property names before padding - Implemented
_backcompat_attr_to_rest_fieldmapping that uses original names when available, falling back to attribute names otherwise - Enhanced serialization functions to use backward-compatible names for attribute lists and dictionaries
- Added comprehensive test matrix covering all combinations of wire names, attribute names, TSP names, visibility, and structure variations
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| sdk/core/azure-core/tests/test_serialization.py | Adds comprehensive test matrix (TestBackcompatPropertyMatrix) covering all combinations of backcompat scenarios including regular, nested, and flattened models with different wire names, padded attributes, and readonly properties |
| sdk/core/azure-core/tests/specs_sdk/modeltypes/modeltypes/_utils/model_base.py | Implements _backcompat_attr_to_rest_field mapping in Model class initialization, adds _get_backcompat_attribute_name helper method, and extends _RestField and rest_field to accept original_tsp_name parameter |
| sdk/core/azure-core/azure/core/serialization.py | Adds _get_backcompat_attr_to_rest_field helper function and updates _get_flattened_attribute, attribute_list, and as_attribute_dict to use backcompat mappings for proper property name resolution |
sdk/core/azure-core/tests/specs_sdk/modeltypes/modeltypes/_utils/model_base.py
Outdated
Show resolved
Hide resolved
sdk/core/azure-core/tests/specs_sdk/modeltypes/modeltypes/_utils/model_base.py
Outdated
Show resolved
Hide resolved
API Change CheckAPIView identified API level changes in this PR and created the following API reviews |
…into fix_backcompat_padding
fix #9013 Related PR: - [ ] Azure/azure-sdk-for-python#44084 - [x] #9019 --------- Co-authored-by: iscai-msft <isabellavcai@gmail.com> Co-authored-by: Yuchao Yan <yuchaoyan@microsoft.com>
lmazuel
left a comment
There was a problem hiding this comment.
Didn't look into the details, but this matches the strategy we discussed offline
|
/check-enforcer override |
We are running into issues with the backcompat functions
attribute_listandas_attribute_dictbecause there are some properties that we didn't pad in auto rest generated code (i.e.keys), but that we pad now in tsp generated code. We want to return the old non-padded properties in this case