Skip to content

Fix AttributeError in az extension update when extension has missing metadata from partial install - #33361

Closed
Aditya Pujara (a0x1ab) with Copilot wants to merge 3 commits into
devfrom
copilot/fix-azure-devops-extension-update
Closed

Fix AttributeError in az extension update when extension has missing metadata from partial install#33361
Aditya Pujara (a0x1ab) with Copilot wants to merge 3 commits into
devfrom
copilot/fix-azure-devops-extension-update

Conversation

Copilot AI commented May 12, 2026

Copy link
Copy Markdown
Contributor

az extension update crashes with AttributeError: 'NoneType' object has no attribute 'get' when an extension directory exists but metadata is absent — e.g., after interrupting az extension add mid-way. Root cause: get_version() unconditionally calls self.metadata.get('version') without a None guard.

Changes

  • extension/__init__.py — Guard get_version() in both WheelExtension and DevExtension against None metadata:
    def get_version(self):
        return self.metadata.get('version') if self.metadata else None
  • extension/operations.pyupdate_extension():
    • Emit a logger.warning when cur_version is None, indicating the extension may be partially installed and the update will attempt to repair it
    • Fix rollback error message to display "unknown" instead of None when version is unavailable

Testing Guide

# Simulate partial install: create extension dir with a *.dist-info but no valid METADATA,
# then run:
az extension update --name <ext>
# Should proceed with a warning instead of crashing

Unit tests added:

  • test_wheel_get_version_with_none_metadataget_version() returns None when metadata is None
  • test_update_extension_with_corrupted_metadataupdate_extension() logs warning and successfully reinstalls when get_version() returns None

History Notes

[Core] az extension update: Fix AttributeError crash when extension has missing or corrupted metadata due to interrupted installation


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

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • azcliprod.blob.core.windows.net
    • Triggering command: /usr/bin/python python -m pytest src/azure-cli-core/azure/cli/core/tests/test_extension.py -v (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented May 12, 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 May 12, 2026

Copy link
Copy Markdown
️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

Copilot AI and others added 2 commits May 12, 2026 05:11
…tall

Guard get_version() in WheelExtension and DevExtension against None
metadata. Add warning in update_extension() when metadata is missing.
Fix rollback message to handle unknown version gracefully.

Fixes: az extension update crashes with AttributeError when extension
was partially installed (interrupted mid-way).

Agent-Logs-Url: https://github.com/Azure/azure-cli/sessions/defa69dc-f897-4a91-975d-3bb1ca805404

Co-authored-by: a0x1ab <59631311+a0x1ab@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with az extension update for azure-devops Fix AttributeError in az extension update when extension has missing metadata from partial install May 12, 2026
@yonzhan

Copy link
Copy Markdown
Collaborator

extension update

@azclibot

Copy link
Copy Markdown
Collaborator

Closing this PR. It was generated by an earlier version of our automated bug-fix pipeline whose live-test step ran whole-module tests, which produced mis-targeted and environmental failures unrelated to the change. The pipeline now runs only the test files touched by the PR. This issue will be re-worked from scratch by the updated pipeline.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

az extension update --name azure-devops

5 participants