Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[http-client-python] Fix deserialization subtype #4716

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
msyyc marked this conversation as resolved.
Show resolved Hide resolved
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
Loading