Skip to content

todict: Include additional properties of TypeSpec-generated models in command output - #34492

Open
Бат-Орших (orshih6) wants to merge 1 commit into
Azure:devfrom
orshih6:contribot/issue-34482
Open

Бат-Орших (orshih6) wants to merge 1 commit into
Azure:devfrom
orshih6:contribot/issue-34482

Conversation

@orshih6

@orshih6 Бат-Орших (orshih6) commented Nov 24, 2026 •

Copy link
Copy Markdown

Related command
az stack group create / az stack sub create / az stack mg create (and any command whose output contains TypeSpec-generated models with additional properties)

Description
The TypeSpec-model branch of todict builds its output only from attribute_list(obj), which covers declared fields only. TypeSpec models keep their data in a mapping keyed by REST name. Keys without a declared field are additional properties, and they were silently dropped. The typical case is a model defined as model X is Record<T>, which has no declared fields. For example, DeploymentExtensionConfig in azure-mgmt-resource-deploymentstacks always rendered as {} in az stack group create output. An inline Record<T> property is not affected, because it deserializes to a plain dict.

After converting the declared attributes, todict now also walks the model's keys. Any key that is not the REST name of a declared field gets added to the result, with its value converted recursively by todict. These keys are kept as they are, the same as dict keys, and no camel-case conversion is applied. Declared fields are unchanged, so existing output doesn't change.

Notes on the two suppressions:

  • # pylint: disable=protected-access on obj._attr_to_rest_field: generated TypeSpec models expose no public API for the set of declared REST names. The _is_model check right above already relies on the same private generator contract.
  • self.skipTest(...) in TestTodictTypeSpecModel: the tests use real generated models from azure-mgmt-resource-deploymentstacks. That package is installed with azure-cli but not with standalone azure-cli-core, so the tests skip when it's missing.

Testing Guide
New unit tests in src/azure-cli-core/azure/cli/core/tests/test_util.py (TestTodictTypeSpecModel):

  • A Record<T> model (DeploymentExtensionConfig) now serializes to its entries instead of {}.
  • A nested model with both declared fields and extra keys keeps both, with and without the remove_additional_prop_layer post-processor.
pytest src/azure-cli-core/azure/cli/core/tests/test_util.py -k TestTodictTypeSpecModel

History Notes
[Core] Include additional properties of TypeSpec-generated models in command output


This checklist is used to make sure that common guidelines for a pull request are followed.

Fixes #34482


This change was prepared with an AI coding agent (Claude) and opened automatically after an automated review, so no person has read it yet. I'm happy to make any changes you'd like.

…in command output

Signed-off-by: Бат-Орших <34618353+orshih6@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 10:59
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the customer-reported Issues that are reported by GitHub users external to the Azure organization. label Nov 24, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

Thank you for your contribution Бат-Орших (@orshih6)! We will review the pull request and get back to you soon.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the change preserving additional SDK model properties in CLI output.

No open issues 🎉

What changed in this PR

Fixes #34482 by preserving additional properties from TypeSpec-generated SDK models in CLI output, including deployment-stack configuration previously rendered as {}.

Changes:

  • Extends todict to recursively convert undeclared model keys while preserving their names and declared-field precedence.
  • Adds SDK-dependent tests for record-style models and nested additional properties, including post-processing.
File Description
src/​azure-cli-core/​azure/​cli/​core/​util.py Includes additional model properties before final post-processing.
src/​azure-cli-core/​azure/​cli/​core/​tests/​test_util.py Adds regression tests using deployment-stacks models; skips when the SDK is unavailable.

Review effort: Balanced

@yonzhan

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@orshih6

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@x-engineering-agent

Copy link
Copy Markdown
Contributor

Бат-Орших (@orshih6) Could you please fix the CI failure first?

@orshih6

Copy link
Copy Markdown
Author

@x-engineering-agent[bot] The description now follows the PR template, with History Notes and the reasons for the two suppressions. I couldn't run the build check here, but azure-cli-core tests show no new failures from this change, so I think the build failed because of the format check. The title also needs the component prefix: "[Core] todict: Include additional properties of TypeSpec-generated models in command output". That should get both checks passing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Additional properties are omitted from SDK resource payloads with some TSP setups.

5 participants