Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/azure-cli/azure/cli/command_modules/vm/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,14 @@ def _check_subnet(s):
subnet_exists = \
check_existence(cmd.cli_ctx, subnet, rg, 'Microsoft.Network', 'subnets', vnet, 'virtualNetworks')

if not subnet_exists:
from azure.cli.command_modules.network.aaz.latest.network.vnet import Show as VNetShow
Copy link

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

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

The import statement is placed inside a conditional block that only executes when subnet doesn't exist. Consider moving this import to the top of the file to avoid repeated import overhead if this code path is executed multiple times.

Suggested change
from azure.cli.command_modules.network.aaz.latest.network.vnet import Show as VNetShow

Copilot uses AI. Check for mistakes.
cli_api_version = VNetShow._aaz_info["version"]
Copy link

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

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

Accessing private attributes (indicated by underscore prefix) like _aaz_info creates a tight coupling and may break if the internal structure changes. Consider using a public API or method to retrieve the version information.

Suggested change
cli_api_version = VNetShow._aaz_info["version"]
# Use public API to get version if available
if hasattr(VNetShow, "get_version") and callable(getattr(VNetShow, "get_version")):
cli_api_version = VNetShow.get_version()
elif hasattr(VNetShow, "version"):
cli_api_version = VNetShow.version
else:
# Fallback to private attribute with warning
logger.warning("Accessing private attribute _aaz_info['version']. Consider updating to use a public API if available.")
cli_api_version = VNetShow._aaz_info["version"]

Copilot uses AI. Check for mistakes.

subnet_exists = \
check_existence(cmd.cli_ctx, subnet, rg, 'Microsoft.Network', 'subnets', vnet, 'virtualNetworks',
api_version=cli_api_version)

if subnet_is_id and not subnet_exists:
raise CLIError("Subnet '{}' does not exist.".format(subnet))
if subnet_exists:
Expand Down
Loading