{Compute} Fix ModuleNotFoundError by removing unnecessary gallery_image_versions - #33150
Julie Zhu (yanzhudd) merged 11 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.
Aditya Pujara (a0x1ab)
left a comment
There was a problem hiding this comment.
Review: PR #33150 — Remove unnecessary gallery_image_versions operation group
✅ All 50 CI checks passed. No live tests needed (no new test files).
Summary of changes
- Removes
gallery_image_versionsfrom the API profile map in_shared.py, eliminating theModuleNotFoundErrorroot cause. - Drops
cf_gallery_image_versionsclient factory and thecompute_gallery_image_versions_sdkCliCommandType. - Strips
operation_group='gallery_image_versions'from allargument_context/command_groupcalls, so those code paths no longer attempt to resolve the now-absent profile entry. - Simplifies
create_image_versionincustom.pyby collapsing thecmd.supported_api_version()version-guard ladder into a single unconditional code path (safe since the minimum API is alreadymin_api='2018-06-01'on the command group, and the dropped guards were for≥2019-07-01/≥2020-09-30etc., all of which are satisfied by any supported SDK version). - Replaces the model-resolved
ReplicationModeenum with an inline["Full", "Shallow"]list — acceptable given the enum only ever had those two values.
Assessment
The fix is targeted and correct. The ModuleNotFoundError was caused by the framework trying to look up API version 2024-03-03 for gallery_image_versions in azure.mgmt.compute, which no longer exposes that sub-client at that version. Removing the profile entry and routing the commands through the default compute client resolves the error cleanly.
No correctness issues found. Ready to merge. Copilot
Posted by agent-assist (autonomous bug-fix pipeline).
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
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.
🤖 PR Validation — ️✔️ All clear