Skip to content

{Compute} Fix ModuleNotFoundError by removing unnecessary gallery_image_versions#33150

Open
JaysonTaiMicrosoft wants to merge 8 commits into
Azure:devfrom
JaysonTaiMicrosoft:fix-module-not-found-error
Open

{Compute} Fix ModuleNotFoundError by removing unnecessary gallery_image_versions#33150
JaysonTaiMicrosoft wants to merge 8 commits into
Azure:devfrom
JaysonTaiMicrosoft:fix-module-not-found-error

Conversation

@JaysonTaiMicrosoft

Copy link
Copy Markdown
Contributor

Related command
az vm list --debug

Description

Remove unnecessary references to gallery_image_versions for already AAZ migrated sig image version commands causing ModuleNotFound errors
image

Testing Guide

Run az vm list --debug there should no longer be a ModuleNotFoundError

History Notes


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

@JaysonTaiMicrosoft JaysonTaiMicrosoft self-assigned this Apr 8, 2026
Copilot AI review requested due to automatic review settings April 8, 2026 07:20
@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented Apr 8, 2026

Copy link
Copy Markdown
️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.13
️✔️acs
️✔️latest
️✔️3.12
️✔️3.13
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.13
️✔️ams
️✔️latest
️✔️3.12
️✔️3.13
️✔️apim
️✔️latest
️✔️3.12
️✔️3.13
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.13
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️aro
️✔️latest
️✔️3.12
️✔️3.13
️✔️backup
️✔️latest
️✔️3.12
️✔️3.13
️✔️batch
️✔️latest
️✔️3.12
️✔️3.13
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.13
️✔️billing
️✔️latest
️✔️3.12
️✔️3.13
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.13
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.13
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.13
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.13
️✔️config
️✔️latest
️✔️3.12
️✔️3.13
️✔️configure
️✔️latest
️✔️3.12
️✔️3.13
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.13
️✔️container
️✔️latest
️✔️3.12
️✔️3.13
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.13
️✔️core
️✔️latest
️✔️3.12
️✔️3.13
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.13
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.13
️✔️dls
️✔️latest
️✔️3.12
️✔️3.13
️✔️dms
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.13
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.13
️✔️find
️✔️latest
️✔️3.12
️✔️3.13
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.13
️✔️identity
️✔️latest
️✔️3.12
️✔️3.13
️✔️iot
️✔️latest
️✔️3.12
️✔️3.13
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.13
️✔️lab
️✔️latest
️✔️3.12
️✔️3.13
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️maps
️✔️latest
️✔️3.12
️✔️3.13
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.13
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.13
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.13
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.13
️✔️network
️✔️latest
️✔️3.12
️✔️3.13
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.13
️✔️postgresql
️✔️latest
️✔️3.12
️✔️3.13
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.13
️✔️profile
️✔️latest
️✔️3.12
️✔️3.13
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.13
️✔️redis
️✔️latest
️✔️3.12
️✔️3.13
️✔️relay
️✔️latest
️✔️3.12
️✔️3.13
️✔️resource
️✔️latest
️✔️3.12
️✔️3.13
️✔️role
️✔️latest
️✔️3.12
️✔️3.13
️✔️search
️✔️latest
️✔️3.12
️✔️3.13
️✔️security
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.13
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.13
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.13
️✔️sql
️✔️latest
️✔️3.12
️✔️3.13
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.13
️✔️storage
️✔️latest
️✔️3.12
️✔️3.13
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.13
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.13
️✔️util
️✔️latest
️✔️3.12
️✔️3.13
️✔️vm
️✔️latest
️✔️3.12
️✔️3.13

@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented Apr 8, 2026

Copy link
Copy Markdown
⚠️AzureCLI-BreakingChangeTest
⚠️vm
rule cmd_name rule_message suggest_message
⚠️ 1008 - ParaPropAdd sig image-version create cmd sig image-version create update parameter replication_mode: added property choices=['Full', 'Shallow']

@yonzhan

yonzhan commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions

github-actions Bot commented Apr 8, 2026

Copy link
Copy Markdown

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).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

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.

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 for sig image-version.
  • Removed gallery_image_versions-scoped model/argument context usage and replaced the ReplicationMode model enum with an explicit enum list.
  • Dropped the gallery_image_versions API-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.

Comment on lines +5683 to +5689
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

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@JaysonTaiMicrosoft

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree company="Microsoft"

Comment on lines -5683 to -5685
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

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.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes I agree, I have removed it now.

@a0x1ab a0x1ab left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 the gallery_image_versions API version entry that was causing the debug-mode module lookup to fail.
  • _client_factory.py / commands.py: Removes the now-unused cf_gallery_image_versions factory and compute_gallery_image_versions_sdk command type.
  • _actions.py: Drops the unused _compute_client_factory import.
  • _params.py: Removes operation_group='gallery_image_versions' from argument contexts and replaces the ReplicationMode SDK model lookup (which required the operation group) with hardcoded ['Full', 'Shallow'] strings.
  • custom.py: Simplifies create_image_version by removing API-version branching for pre-2019-07-01 and pre-2022-03-03 paths, keeping only the modern code path.

Minor concerns

  1. Hardcoded enum strings: get_enum_type(['Full', 'Shallow']) replaces get_enum_type(ReplicationMode). This loses compile-time safety from the SDK model. Consider importing ReplicationMode directly from the SDK without the operation group context.
  2. Removed API-version guards: The old cmd.supported_api_version(min_api='2022-03-03', ...) and min_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).

@a0x1ab a0x1ab left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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_versions from the API profile map in _shared.py, eliminating the ModuleNotFoundError root cause.
  • Drops cf_gallery_image_versions client factory and the compute_gallery_image_versions_sdk CliCommandType.
  • Strips operation_group='gallery_image_versions' from all argument_context / command_group calls, so those code paths no longer attempt to resolve the now-absent profile entry.
  • Simplifies create_image_version in custom.py by collapsing the cmd.supported_api_version() version-guard ladder into a single unconditional code path (safe since the minimum API is already min_api='2018-06-01' on the command group, and the dropped guards were for ≥2019-07-01 / ≥2020-09-30 etc., all of which are satisfied by any supported SDK version).
  • Replaces the model-resolved ReplicationMode enum 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).

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

Labels

act-observability-squad Auto-Assign Auto assign by bot Compute az vm/vmss/image/disk/snapshot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ModuleNotFoundError on vm commands when using --debug flag

6 participants