Skip to content

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

Open
Copilot wants to merge 9 commits intomainfrom
copilot/add-test-case-typespec-10063
Open

[python] Add mock API tests for XML scenarios from PR #10063 and fix XML serialization bugs (WIP)#10098
Copilot wants to merge 9 commits intomainfrom
copilot/add-test-case-typespec-10063

Conversation

Copy link
Contributor

Copilot AI commented Mar 19, 2026

  • Bump @typespec/http-specs to 0.1.0-alpha.35-dev.5
  • 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)
  • Extract local variables for double-lookup patterns in _get_element/_get_wrapped_element
  • Add note about ET._namespace_map silent fallback behavior
  • Remove .venv_test from .gitignore (local dev leftover)
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

pkg-pr-new bot commented Mar 20, 2026

Open in StackBlitz

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

commit: 90b7ab0

@github-actions
Copy link
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. Tests for unwrapped model array serialization and namespace handling are skipped pending generator bug fixes.

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

…eserved prefix

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 [python] Add mock API tests for XML scenarios from PR #10063 and fix XML serialization bugs Mar 20, 2026
Copilot AI requested a review from msyyc March 20, 2026 02:54
@msyyc msyyc changed the title [python] Add mock API tests for XML scenarios from PR #10063 and fix XML serialization bugs [python] Add mock API tests for XML scenarios from PR #10063 and fix XML serialization bugs (WIP) Mar 20, 2026
@msyyc msyyc requested a review from Copilot March 23, 2026 06:19
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

Adds Python mock API coverage for new @typespec/http-specs XML scenarios and updates the Python generator’s XML runtime template to fix serialization/deserialization issues needed by those scenarios.

Changes:

  • Bump @typespec/http-specs to 0.1.0-alpha.35-dev.5 to pick up new XML scenarios.
  • Add new sync + async mock API tests covering renamed properties/attributes, nested models, array wrapping/unwrapping, and namespaces.
  • Fix XML runtime template behaviors around namespace handling and element naming for unwrapped model arrays.

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/http-client-python/package.json Bumps @typespec/http-specs dependency version.
packages/http-client-python/package-lock.json Locks updated @typespec/http-specs tarball + integrity.
packages/http-client-python/generator/test/generic_mock_api_tests/test_payload_xml.py Adds new sync mock API XML scenarios.
packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_payload_xml_async.py Adds async equivalents of new XML scenarios.
packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2 Fixes XML namespace reading and array-item element naming; adds safe namespace registration fallback in element creation.
.gitignore Ignores .venv_test.
.chronus/changes/python-xml-test-cases-2026-3-19-22-47-48.md Adds changelog entry for the internal change.
Files not reviewed (1)
  • packages/http-client-python/package-lock.json: Language not supported

…model_base.py.jinja2

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

@msyyc msyyc left a comment

Choose a reason for hiding this comment

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

Code Review

Overall the tests are well-structured and consistent with existing patterns. The 4 bug fixes in model_base.py.jinja2 are well-reasoned. A few issues worth addressing:

🔴 Bug: itemNs vs itemsNs key mismatch (deserialization ↔ serialization)

File: model_base.py.jinja2 — deserialization path (~line 648) vs serialization path (~line 1330)

Serialization consistently uses plural itemsNs/itemsName/itemsPrefix, but the existing deserialization code reads itemNs (singular). This PR didn't introduce the bug but touches the surrounding code and would be a good opportunity to fix it. If a model declares itemsNs metadata, deserialization will silently ignore it.

🟡 Empty-string namespace treated as falsy in or chains

Multiple new lines use patterns like:

xml_ns = prop_meta.get("ns") or prop_meta.get("namespace")
parent_meta.get("itemsNs") or parent_meta.get("ns") or parent_meta.get("namespace")

If a key is explicitly set to "" (valid in XML — means "no namespace"), the or chain falls through to the next value instead of honoring the empty string. Safer pattern:

xml_ns = prop_meta.get("ns")
if xml_ns is None:
    xml_ns = prop_meta.get("namespace")

🟡 Private API ET._namespace_map in _create_xml_element

The try/except ValueError fallback uses getattr(ET, "_namespace_map", None) — a private CPython implementation detail. This works today but could break in future Python versions. If _namespace_map is absent, the prefix silently becomes auto-generated (ns0, ns1…) with no warning. Consider adding a log or comment about the silent fallback behavior.

Minor

  • Changelog entry still says "skipped pending generator bug fixes" even though the bugs were subsequently fixed and all skips removed. Should be updated to reflect the current state.
  • .gitignore addition of .venv_test — is this intentional or a leftover from local development?

Copilot AI requested a review from msyyc March 23, 2026 06:35
@msyyc
Copy link
Contributor

msyyc commented Mar 23, 2026

@copilot analyze the review comment #10098 (review).

…cks, improve namespace_map comment, remove .venv_test from .gitignore

Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/0b94f8d4-fb48-435f-a266-158971884321
Copy link
Contributor Author

Copilot AI commented Mar 23, 2026

Code Review

Overall the tests are well-structured and consistent with existing patterns. The 4 bug fixes in model_base.py.jinja2 are well-reasoned. A few issues worth addressing:...

Addressed in e02d171:

  • itemNsitemsNs (🔴): Fixed the key mismatch in the deserialization path. Also restructured the unwrapped-array block so when itemsNs is absent the existing property namespace still applies to the items name.
  • Empty-string namespace or chains (🟡): Replaced all prop_meta.get("ns") or prop_meta.get("namespace") patterns with is None checks (across all 8 affected sites in deserialization and serialization paths). Also extracted local variables to avoid double-lookups flagged in code review.
  • ET._namespace_map silent fallback (🟡): Added a comment noting that if _namespace_map is absent (e.g. alternative Python implementations) ET will silently auto-generate a prefix.
  • .venv_test in .gitignore: Removed — was a local development leftover.

@copilot analyze the review comment #10098 (review).

All four points from the review have been addressed in e02d171. See the reply on the review comment for details.

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

Copilot reviewed 5 out of 6 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • packages/http-client-python/package-lock.json: Language not supported

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

4 participants