Skip to content

[python] Add mock API tests for XML scenarios from PR #10063 and fix XML serialization bugs#10098

Merged
iscai-msft merged 15 commits into
mainfrom
copilot/add-test-case-typespec-10063
Mar 31, 2026
Merged

[python] Add mock API tests for XML scenarios from PR #10063 and fix XML serialization bugs#10098
iscai-msft merged 15 commits into
mainfrom
copilot/add-test-case-typespec-10063

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 19, 2026

  • Bump @typespec/http-specs to 0.1.0-alpha.35
  • Add 11 new XML scenario tests (sync + async)
  • Fix unwrapped model array element naming
  • Fix namespace key mismatch (DPG "namespace" vs runtime "ns")
  • Fix default-namespace propagation semantics
  • Fix Python ET reserved prefix (ns\d+)
  • Remove all 4 @pytest.mark.skip markers — 26/26 tests pass
  • Update changelog entry to reflect generator fixes and all-green tests
  • Fix itemNsitemsNs key mismatch in deserialization (red bug)
  • Replace all or chains for namespace lookups with is None checks (handles empty-string namespaces correctly)
  • Add note about ET._namespace_map silent fallback behavior
  • Remove .venv_test from .gitignore (local dev leftover)
  • Extract _get_xml_ns helper to eliminate 9x duplicated ns/namespace fallback pattern
  • Merge main branch, resolve conflicts using main's dependency versions
  • Fix mypy Optional[Any] type error in unwrapped array deserialization block
Original prompt

This section details on the original issue you should resolve

<issue_title>[python] add test case for #10063
</issue_title>
<issue_description>follow skill https://github.com/microsoft/typespec/blob/main/.github/skills/python-sdk-spector-mock-api-tests/SKILL.md to write test case for #10063
</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits March 19, 2026 22:48
Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Mar 19, 2026
Copilot AI changed the title [WIP] Add test case for typespec pull request 10063 [python] Add mock API tests for XML scenarios from PR #10063 Mar 19, 2026
Copilot AI requested a review from msyyc March 19, 2026 22:53
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 20, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-python@10098

commit: 225dd91

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 20, 2026

All changed packages have been documented.

  • @typespec/http-client-python
Show changes

@typespec/http-client-python - internal ✏️

Add mock API test cases for XML scenarios introduced in #10063, covering: renamed property, nested model, renamed nested model, wrapped primitive with custom item names, model array variants (wrapped/unwrapped/renamed), renamed attribute, namespace, and namespace-on-properties. Fix XML serialization/deserialization bugs: unwrapped model array element naming, namespace key mismatch between DPG models and the runtime template, default-namespace propagation semantics, and handling of Python-reserved namespace prefixes.

@azure-sdk
Copy link
Copy Markdown
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

…mespace fallback pattern

Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/c063fa73-5d6e-4cbd-ae5b-c5a2d188abba
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 24, 2026

Review: model_base.py.jinja2 - duplicated namespace fallback logic

The bug fixes in this PR (namespace key compat, ET.register_namespace ValueError handling, items naming) are all correct. The...

Extracted _get_xml_ns(meta) helper in 460cfdb. All 9 duplicated blocks replaced with one-liner calls; net -12 lines. The identical deser/discriminator blocks at lines 633-641 and 774-780 now both read:

xml_ns = _get_xml_ns(prop_meta)
if xml_ns is None and not model_meta.get("prefix"):
    xml_ns = _get_xml_ns(model_meta)

The old-style "ns" propagation block at line 1310 intentionally remains a raw .get("ns") check since it explicitly skips DPG "namespace" models.

@copilot fix with review comment #10098 (review)

Done in 460cfdb — extracted _get_xml_ns helper, replacing all 9 duplicated ns/namespace fallback blocks.

Copilot AI requested a review from msyyc March 24, 2026 02:40
Comment thread packages/http-client-python/package.json Outdated
Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Copilot AI changed the title [python] Add mock API tests for XML scenarios from PR #10063 and fix XML serialization bugs (WIP) [python] Add mock API tests for XML scenarios from PR #10063 and fix XML serialization bugs Mar 31, 2026
Copilot AI requested a review from msyyc March 31, 2026 02:43
@msyyc
Copy link
Copy Markdown
Contributor

msyyc commented Mar 31, 2026

@copilot fix the following CI error:

2026-03-31T03:17:56.4066343Z generated\encode-array\encode\array\_utils\model_base.py:634: error: Unsupported operand types for + ("str" and "None")  [operator]
2026-03-31T03:17:56.4114450Z generated\encode-array\encode\array\_utils\model_base.py:634: note: Right operand is of type "Optional[Any]"
2026-03-31T03:17:56.8111446Z Found 1 error in 1 file (checked 25 source files)
2026-03-31T03:17:56.8305397Z ERROR:root:encode exited with mypy error 1
2026-03-31T03:17:57.0659412Z Success: no issues found in 7 source files
2026-03-31T03:17:57.3856885Z Success: no issues found in 5 source files
2026-03-31T03:17:58.4850745Z ERROR:root:client exited with mypy error 1
2026-03-31T03:17:58.4851655Z generated\client-overload\client\overload\_utils\model_base.py:634: error: Unsupported operand types for + ("str" and "None")  [operator]
2026-03-31T03:17:59.3867577Z ERROR:root:encode exited with mypy error 1
2026-03-31T03:17:59.3868340Z generated\client-overload\client\overload\_utils\model_base.py:634: note: Right operand is of type "Optional[Any]"
2026-03-31T03:18:01.9578359Z ERROR:root:encode exited with mypy error 1
2026-03-31T03:18:01.9579337Z Found 1 error in 1 file (checked 23 source files)
2026-03-31T03:18:01.9579954Z Success: no issues found in 7 source files
2026-03-31T03:18:01.9580632Z generated\encode-bytes\encode\bytes\_utils\model_base.py:634: error: Unsupported operand types for + ("str" and "None")  [operator]
2026-03-31T03:18:01.9581417Z generated\encode-bytes\encode\bytes\_utils\model_base.py:634: note: Right operand is of type "Optional[Any]"
2026-03-31T03:18:01.9582099Z Success: no issues found in 7 source files
2026-03-31T03:18:01.9582661Z Found 1 error in 1 file (checked 56 source files)
2026-03-31T03:18:01.9583232Z Success: no issues found in 5 source files
2026-03-31T03:18:01.9583966Z Success: no issues found in 5 source files
2026-03-31T03:18:01.9584508Z Success: no issues found in 7 source files
2026-03-31T03:18:01.9585057Z Success: no issues found in 5 source files
2026-03-31T03:18:01.9585730Z generated\encode-datetime\encode\datetime\_utils\model_base.py:634: error: Unsupported operand types for + ("str" and "None")  [operator]
2026-03-31T03:18:01.9586535Z generated\encode-datetime\encode\datetime\_utils\model_base.py:634: note: Right operand is of type "Optional[Any]"
2026-03-31T03:18:01.9587211Z Success: no issues found in 5 source files
2026-03-31T03:18:01.9587733Z Found 1 error in 1 file (checked 48 source files)

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

@copilot fix the following CI error:

...

Fixed in ab1635e. The mypy error was caused by xml_name = prop_meta.get("itemsName") returning Optional[Any], then being used in string concatenation. The fix saves the .get() result to a local variable _items_name and assigns it to xml_name inside the truthy guard, allowing mypy to narrow the type correctly.

Extract helper functions from Model.__init__ and _get_element to resolve
too-many-branches, too-many-statements, and too-many-nested-blocks lint
violations introduced by XML namespace handling improvements.

Changes:
- Extract _init_from_xml() from Model.__init__ (21->6 branches, 55->15 stmts)
- Extract _set_xml_attribute() from _get_element (removes try/except nesting)
- Add _resolve_xml_ns() consolidating 3-line ns resolution pattern (3 call sites)
- Add _safe_register_namespace() standardizing ET.register_namespace error handling
- Fix _get_xml_ns() docstring (add :param:, :returns:, :rtype:)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@iscai-msft iscai-msft enabled auto-merge March 31, 2026 19:08
@iscai-msft iscai-msft added this pull request to the merge queue Mar 31, 2026
Merged via the queue into main with commit 64d27b7 Mar 31, 2026
39 checks passed
@iscai-msft iscai-msft deleted the copilot/add-test-case-typespec-10063 branch March 31, 2026 20:08
msyyc added a commit that referenced this pull request Apr 1, 2026
…XML serialization bugs (#10098)

- [x] Bump @typespec/http-specs to 0.1.0-alpha.35
- [x] Add 11 new XML scenario tests (sync + async)
- [x] Fix unwrapped model array element naming
- [x] Fix namespace key mismatch (DPG "namespace" vs runtime "ns")
- [x] Fix default-namespace propagation semantics
- [x] Fix Python ET reserved prefix (ns\d+)
- [x] Remove all 4 @pytest.mark.skip markers — 26/26 tests pass
- [x] Update changelog entry to reflect generator fixes and all-green
tests
- [x] Fix `itemNs` → `itemsNs` key mismatch in deserialization (red bug)
- [x] Replace all `or` chains for namespace lookups with `is None`
checks (handles empty-string namespaces correctly)
- [x] Add note about `ET._namespace_map` silent fallback behavior
- [x] Remove `.venv_test` from `.gitignore` (local dev leftover)
- [x] Extract `_get_xml_ns` helper to eliminate 9x duplicated
ns/namespace fallback pattern
- [x] Merge main branch, resolve conflicts using main's dependency
versions
- [x] Fix mypy `Optional[Any]` type error in unwrapped array
deserialization block

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *This section details on the original issue you should resolve*
> 
> <issue_title>[python] add test case for
#10063
> </issue_title>
> <issue_description>follow skill
https://github.com/microsoft/typespec/blob/main/.github/skills/python-sdk-spector-mock-api-tests/SKILL.md
to write test case for #10063
> </issue_description>
> 
> ## Comments on the Issue (you are @copilot in this section)
> 
> <comments>
> </comments>
> 


</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes #10097

<!-- START COPILOT CODING AGENT TIPS -->
---

🔒 GitHub Advanced Security automatically protects Copilot coding agent
pull requests. You can protect all pull requests by enabling Advanced
Security for your repositories. [Learn more about Advanced
Security.](https://gh.io/cca-advanced-security)

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Co-authored-by: Yuchao Yan <yuchaoyan@microsoft.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: iscai-msft <isabellavcai@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:python Issue for the Python client emitter: @typespec/http-client-python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[python] add test case for https://github.com/microsoft/typespec/pull/10063

6 participants