[Microsoft.ChangeSafety][BugFix] fix additional data parsing issue#9901
Conversation
…ted JSON The --additional-data argument was defined as AAZObjectArg with no child fields, causing 'Model AAZObjectArg has no field named safeFly' errors. The --change-definition details field had the same issue, rejecting ApiOperations payloads with 'no field named operations'. Changes: - Change additional_data from AAZObjectArg to AAZFreeFormDictArg - Change change_definition.details from AAZObjectArg to AAZFreeFormDictArg - Change corresponding AAZObjectType to AAZFreeFormDictType in builders and response schemas across create, update, show, and list - Add content injection for additionalData in custom.py (same pattern as changeDefinition) to work around AAZ builder serialization limitation - Add tests for SafeFly payload, links, and orchestration-tool arguments - Bump version to 1.0.0b2 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
| rule | cmd_name | rule_message | suggest_message |
|---|---|---|---|
| changesafety changerecord create | cmd changesafety changerecord create update parameter additional_data: updated property aaz_type from AAZObjectArg to AAZFreeFormDictArg |
||
| changesafety changerecord create | cmd changesafety changerecord create update parameter additional_data: updated property type from Object to Dict<String,Any> |
||
| changesafety changerecord update | cmd changesafety changerecord update update parameter additional_data: updated property aaz_type from AAZObjectArg to AAZFreeFormDictArg |
||
| changesafety changerecord update | cmd changesafety changerecord update update parameter additional_data: updated property type from Object to Dict<String,Any> |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR updates the ChangeSafety CLI extension to properly accept and round-trip free-form nested JSON for --additional-data (and changeDefinition.details), including a content-injection workaround for an AAZ serialization limitation, and adds scenario tests covering SafeFly-like payloads.
Changes:
- Bump extension version to
1.0.0b2and document the release notes. - Switch
additional_dataandchange_definition.detailsto free-form dict argument/schema types in AAZ-generated commands. - Inject
additionalDatainto request payloads during Create/Update and add tests for nested JSON, links, and orchestration tool.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/azure-changesafety/setup.py | Version bump for the next beta release. |
| src/azure-changesafety/HISTORY.rst | Release notes describing the free-form JSON fix and injection workaround. |
| src/azure-changesafety/azext_changesafety/custom.py | Implements additionalData capture + injection into request bodies for Create/Update. |
| src/azure-changesafety/azext_changesafety/tests/latest/test_changesafety.py | Extends mocks and adds tests for --additional-data, --links, --orchestration-tool. |
| src/azure-changesafety/azext_changesafety/aaz/latest/changesafety/changerecord/_create.py | Uses free-form dict arg/type for additional_data and changeDefinition.details. |
| src/azure-changesafety/azext_changesafety/aaz/latest/changesafety/changerecord/_update.py | Uses free-form dict arg/type for additional_data and changeDefinition.details. |
| src/azure-changesafety/azext_changesafety/aaz/latest/changesafety/changerecord/_show.py | Reads additionalData and changeDefinition.details as free-form dict types. |
| src/azure-changesafety/azext_changesafety/aaz/latest/changesafety/changerecord/_list.py | Reads additionalData and changeDefinition.details as free-form dict types. |
| return content | ||
|
|
||
| additional_data = additional_data_value.to_serialized_data() | ||
| if not additional_data: |
| if additional_data: | ||
| self.ctx.set_var( | ||
| 'additional_data', | ||
| additional_data, | ||
| schema_builder=_build_any_type, | ||
| ) |
| # Capture additional_data for injection into request content. | ||
| # The AAZ builder cannot serialize AAZFreeFormDictType, so we | ||
| # store the raw value and inject it via the content property. | ||
| additional_data_arg = getattr(self.ctx.args, "additional_data", None) | ||
| if has_value(additional_data_arg): | ||
| additional_data = additional_data_arg.to_serialized_data() | ||
| if additional_data: | ||
| self.ctx.set_var( | ||
| 'additional_data', | ||
| additional_data, | ||
| schema_builder=_build_any_type, | ||
| ) |
| class ChangeRecordsCreateOrUpdateAtSubscriptionLevel( | ||
| _ChangeRecordUpdate.ChangeRecordsCreateOrUpdateAtSubscriptionLevel): | ||
| """Override PUT at subscription level to preserve original changeDefinition.""" | ||
| """Override PUT at subscription level to preserve changeDefinition and inject additionalData.""" | ||
|
|
||
| @property | ||
| def content(self): | ||
| content = super().content | ||
| # Preserve original changeDefinition - it cannot be updated | ||
| return _preserve_change_definition_in_content(content, self.ctx) | ||
| content = _preserve_change_definition_in_content(content, self.ctx) | ||
| content = _inject_additional_data_into_content(content, self.ctx) | ||
| return content |
|
ChangeSafety |
notyashhh
left a comment
There was a problem hiding this comment.
Looks soild, Just a NIT, if anyone passes empty dict {}, it will silently drop so can you update these 2 instances, I can approve and merge it once done!
…ecks
Per review feedback, replace truthiness checks with explicit None checks so
that an explicitly provided empty dict {} is treated as a valid user-supplied
value rather than being silently dropped.
- _inject_additional_data_into_content: 'if not additional_data' -> 'is None'
- ChangeRecordCreate.pre_operations: 'if additional_data' -> 'is not None'
- ChangeRecordUpdate.pre_operations: same fix for consistency (duplicated pattern)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
[Release] Update index.json for extension [ azure-changesafety-1.0.0b2 ] : https://dev.azure.com/msazure/One/_build/results?buildId=166044594&view=results |
…zure#9901) * Fix --additional-data and --change-definition to accept free-form nested JSON The --additional-data argument was defined as AAZObjectArg with no child fields, causing 'Model AAZObjectArg has no field named safeFly' errors. The --change-definition details field had the same issue, rejecting ApiOperations payloads with 'no field named operations'. Changes: - Change additional_data from AAZObjectArg to AAZFreeFormDictArg - Change change_definition.details from AAZObjectArg to AAZFreeFormDictArg - Change corresponding AAZObjectType to AAZFreeFormDictType in builders and response schemas across create, update, show, and list - Add content injection for additionalData in custom.py (same pattern as changeDefinition) to work around AAZ builder serialization limitation - Add tests for SafeFly payload, links, and orchestration-tool arguments - Bump version to 1.0.0b2 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Retrigger CI (transient GitHub 403 incident on prior run) * Address PR nits: use 'is None' / 'is not None' for additional_data checks Per review feedback, replace truthiness checks with explicit None checks so that an explicitly provided empty dict {} is treated as a valid user-supplied value rather than being silently dropped. - _inject_additional_data_into_content: 'if not additional_data' -> 'is None' - ChangeRecordCreate.pre_operations: 'if additional_data' -> 'is not None' - ChangeRecordUpdate.pre_operations: same fix for consistency (duplicated pattern) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Henry Dai <henrydai@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This checklist is used to make sure that common guidelines for a pull request are followed.
Related command
General Guidelines
azdev style <YOUR_EXT>locally? (pip install azdevrequired)python scripts/ci/test_index.py -qlocally? (pip install wheel==0.30.0required)For new extensions:
About Extension Publish
There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update
src/index.jsonautomatically.You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify
src/index.json.