Skip to content

Commit

Permalink
[http-client-python] Fix deserialization subtype (microsoft#4716)
Browse files Browse the repository at this point in the history
  • Loading branch information
msyyc authored Oct 15, 2024
1 parent 4e63496 commit 34624a0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
6 changes: 6 additions & 0 deletions packages/http-client-python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log - @typespec/http-client-python

## 0.3.1

### Bug Fixes

- Avoid change original data when deserialize for polymorphic model

## 0.3.0

### Bump dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ class Model(object):
def _classify(cls, response, objects):
"""Check the class _subtype_map for any child classes.
We want to ignore any inherited _subtype_maps.
Remove the polymorphic key from the initial data.

:param dict response: The initial data
:param dict objects: The class objects
Expand All @@ -518,7 +517,7 @@ class Model(object):

if not isinstance(response, ET.Element):
rest_api_response_key = cls._get_rest_key_parts(subtype_key)[-1]
subtype_value = response.pop(rest_api_response_key, None) or response.pop(subtype_key, None)
subtype_value = response.get(rest_api_response_key, None) or response.get(subtype_key, None)
else:
subtype_value = xml_key_extractor(subtype_key, cls._attribute_map[subtype_key], response)
if subtype_value:
Expand Down
4 changes: 2 additions & 2 deletions packages/http-client-python/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/http-client-python/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typespec/http-client-python",
"version": "0.3.0",
"version": "0.3.1",
"author": "Microsoft Corporation",
"description": "TypeSpec emitter for Python SDKs",
"homepage": "https://typespec.io",
Expand Down

0 comments on commit 34624a0

Please sign in to comment.