[python] Fix XML deserialization for enum/datetime types and add mock API tests#9724
Draft
[python] Fix XML deserialization for enum/datetime types and add mock API tests#9724
Conversation
…n for enum/datetime types Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add test case for Typespec pull request 9660
Fix XML deserialization for enum/datetime types and add mock API tests
Feb 14, 2026
12 tasks
commit: |
Contributor
|
All changed packages have been documented.
Show changes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR #9660 added Spector test cases for XML models with enum and datetime properties (
ModelWithEnum,ModelWithDatetime). This PR adds the corresponding Python SDK mock API tests and fixes XML deserialization bugs uncovered by them.Bug fix: XML deserialization of enum and datetime values
_deserialize_with_callableinmodel_base.py.jinja2failed to extract text fromET.Elementfor non-primitive types. Enum values hit theCaseInsensitiveEnumMetapath which passed the raw Element to the enum constructor, caught theValueError, and returned the Element as the "unknown value". DateTime values similarly passed raw Elements to_deserialize_datetimewhich expects strings.Also added early-return paths for
_DESERIALIZE_MAPPINGand_DESERIALIZE_MAPPING_WITHFORMATfunctions (datetime, duration, bytes, etc.) within theET.Elementblock.Tests
test_model_with_enum— GET/PUT round-trip forModelWithEnumwith extensible union status fieldtest_model_with_datetime— GET validation forModelWithDatetimewith rfc3339/rfc7231 encoded fields (PUT omitted due to pre-existing millisecond precision mismatch inisoformat()serialization)generic_mock_api_tests/Dependency
@typespec/http-specsto0.1.0-alpha.33-dev.2to pick up the new XML enum/datetime Spector cases💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.