Skip to content

[core] add tests and fix backcompat functions#44084

Merged
pvaneck merged 14 commits intoAzure:mainfrom
iscai-msft:fix_backcompat_padding
Dec 8, 2025
Merged

[core] add tests and fix backcompat functions#44084
pvaneck merged 14 commits intoAzure:mainfrom
iscai-msft:fix_backcompat_padding

Conversation

@iscai-msft
Copy link
Contributor

We are running into issues with the backcompat functions attribute_list and as_attribute_dict because 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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_name parameter to _RestField and rest_field to track original TypeSpec property names before padding
  • Implemented _backcompat_attr_to_rest_field mapping 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

@github-actions
Copy link

github-actions bot commented Nov 19, 2025

API Change Check

APIView identified API level changes in this PR and created the following API reviews

azure-core

github-merge-queue bot pushed a commit to microsoft/typespec that referenced this pull request Dec 4, 2025
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>
@iscai-msft iscai-msft requested a review from pvaneck December 4, 2025 22:30
Copy link
Member

@lmazuel lmazuel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't look into the details, but this matches the strategy we discussed offline

@pvaneck
Copy link
Member

pvaneck commented Dec 8, 2025

/check-enforcer override

@pvaneck pvaneck merged commit cbb1db6 into Azure:main Dec 8, 2025
43 of 54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants