{Compute} Fix ModuleNotFoundError by removing unnecessary gallery_image_versions#33150
{Compute} Fix ModuleNotFoundError by removing unnecessary gallery_image_versions#33150JaysonTaiMicrosoft wants to merge 5 commits into
Conversation
️✔️AzureCLI-FullTest
|
|
| rule | cmd_name | rule_message | suggest_message |
|---|---|---|---|
| sig image-version create | cmd sig image-version create update parameter replication_mode: added property choices=['Full', 'Shallow'] |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
There was a problem hiding this comment.
Pull request overview
This PR removes remaining non-AAZ references to the gallery_image_versions Compute SDK operation group from the VM command module, resolving ModuleNotFoundError triggered during command table/argument loading (e.g., az vm list --debug).
Changes:
- Removed the
GalleryImageVersionsOperations-based command type and command group wiring forsig image-version. - Removed
gallery_image_versions-scoped model/argument context usage and replaced theReplicationModemodel enum with an explicit enum list. - Dropped the
gallery_image_versionsAPI-version entry from the core compute SDK profile mapping and removed the unused VM client factory for it.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/azure-cli/azure/cli/command_modules/vm/custom.py |
Simplifies create_image_version by removing API-version branching tied to gallery_image_versions. |
src/azure-cli/azure/cli/command_modules/vm/commands.py |
Removes SDK command type and operation-group binding for sig image-version to avoid importing missing SDK ops. |
src/azure-cli/azure/cli/command_modules/vm/_params.py |
Removes gallery_image_versions model lookup/context and hardcodes replication_mode enum values. |
src/azure-cli/azure/cli/command_modules/vm/_client_factory.py |
Deletes the unused cf_gallery_image_versions client factory. |
src/azure-cli-core/azure/cli/core/profiles/_shared.py |
Removes gallery_image_versions from the compute SDK profile operation-group version map. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| source = {"managed_image": {"id": managed_image}} | ||
| profile["source"] = source | ||
|
|
||
| if managed_image is None and os_snapshot is None and os_vhd_uri is None: | ||
| raise RequiredArgumentMissingError('usage error: Please provide --managed-image or --os-snapshot or --vhd') | ||
|
|
||
| source = os_disk_image = data_disk_images = None |
There was a problem hiding this comment.
In create_image_version, profile["source"] is now set unconditionally using the legacy {managed_image: {id: ...}} shape, but the actual request source is built later via storage_profile["source"] (using {id: ...} / {virtual_machine_id: ...}). Since the AAZ sig image-version create schema doesn’t have a publishing_profile.source field, this assignment is ignored and the source variable name is then re-used for a different payload shape, making the flow harder to follow. Consider removing the profile["source"] assignment and using a distinct variable name for the storage_profile source to avoid shadowing.
…nTaiMicrosoft/azure-cli into fix-module-not-found-error
|
@microsoft-github-policy-service agree company="Microsoft" |
| if not cmd.supported_api_version(min_api='2022-03-03', operation_group='gallery_image_versions'): | ||
| source = {"managed_image": {"id": managed_image}} | ||
| profile["source"] = source |
There was a problem hiding this comment.
This if statement checks whether the API version is earlier than 2022-03-03, and executes the code if it is.
I think we can safely remove these lines.
There was a problem hiding this comment.
Yes I agree, I have removed it now.
a0x1ab
left a comment
There was a problem hiding this comment.
Review: PR #33150 — Fix ModuleNotFoundError by removing unnecessary gallery_image_versions
CI: all 49 checks passed
Summary
The PR fixes a spurious ModuleNotFoundError that appeared in --debug output for VM commands by removing the gallery_image_versions operation group registration throughout the codebase.
Changes look correct
_shared.py: Removes thegallery_image_versionsAPI version entry that was causing the debug-mode module lookup to fail._client_factory.py/commands.py: Removes the now-unusedcf_gallery_image_versionsfactory andcompute_gallery_image_versions_sdkcommand type._actions.py: Drops the unused_compute_client_factoryimport._params.py: Removesoperation_group='gallery_image_versions'from argument contexts and replaces theReplicationModeSDK model lookup (which required the operation group) with hardcoded['Full', 'Shallow']strings.custom.py: Simplifiescreate_image_versionby removing API-version branching for pre-2019-07-01 and pre-2022-03-03 paths, keeping only the modern code path.
Minor concerns
- Hardcoded enum strings:
get_enum_type(['Full', 'Shallow'])replacesget_enum_type(ReplicationMode). This loses compile-time safety from the SDK model. Consider importingReplicationModedirectly from the SDK without the operation group context. - Removed API-version guards: The old
cmd.supported_api_version(min_api='2022-03-03', ...)andmin_api='2019-07-01'branches are deleted. Since the minimum supported profile is well past these dates, this simplification is acceptable.
@copilot please confirm the hardcoded ['Full', 'Shallow'] enum is intentional and won't drift from the SDK definition over time.
Posted by agent-assist (autonomous bug-fix pipeline).
Related command
az vm list --debugDescription
Remove unnecessary references to

gallery_image_versionsfor already AAZ migratedsig image versioncommands causingModuleNotFounderrorsTesting Guide
Run
az vm list --debugthere should no longer be aModuleNotFoundErrorHistory Notes
This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.