Skip to content

Conversation

@bebound
Copy link
Contributor

@bebound bebound commented Apr 11, 2023

Description

Fix #20473

The full error is

Traceback (most recent call last):
  File "C:\Users\kk\Developer\azure-cli\src\azure-cli\azure\cli\__main__.py", line 84, in <module>
    if parse(VERSIONS['versions']['core']['local']) < parse(VERSIONS['versions']['core']['pypi']):  # pylint: disable=line-too-long
KeyError: 'pypi'

So it's easy to fix. But the cause is pretty tricky.

CLI gets latest version from GitHub.

def _update_latest_from_github(versions):
if not check_connectivity(max_retries=0):
return versions, False
success = True
for pkg in ['azure-cli-core', 'azure-cli-telemetry']:
version = get_latest_from_github(pkg)
if not version:
success = False
else:
versions[pkg.replace(COMPONENT_PREFIX, '')]['pypi'] = version
try:
versions[CLI_PACKAGE_NAME]['pypi'] = versions['core']['pypi']
except KeyError:
pass
return versions, success

pypi is added in line 327. If check_connectivity or get_latest_from_github fails, this key does not exist.

A wrong ~/.azure/versionCheck.json is also generated with this content:
{"versions": {"azure-cli": {"local": "2.47.0"}, "core": {"local": "2.47.0"}, "telemetry": {"local": "1.0.8"}}, "update_time": "2023-04-11 17:30:11.402751", "check_time": "2023-03-22 18:05:23.331052"}

PS:
I think az upgrade causes more issues than it resolves.

  • It does not check if new version is available in that distro. CentOS 7 users still see new version available.
  • Make __main__.py complicated.
  • Upgrade introduces many issues, but we can't address them. Upgrade failure may occur due to various reasons. For example: missing source.list file in DEB or permission error when install MSI.

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

@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Apr 11, 2023

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

@azure-client-tools-bot-prd
Copy link

Hi @bebound,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@ghost ghost added Auto-Assign Auto assign by bot Core CLI core infrastructure labels Apr 11, 2023
@ghost ghost requested a review from jiasli April 11, 2023 10:14
@yonzhan
Copy link
Collaborator

yonzhan commented Apr 11, 2023

Core

@ghost ghost requested a review from yonzhan April 11, 2023 10:14
@ghost ghost assigned jiasli Apr 11, 2023
@ghost ghost requested a review from wangzelin007 April 11, 2023 10:14
@ghost ghost added the Installation label Apr 11, 2023
@ghost ghost requested a review from jsntcy April 11, 2023 10:14
@jiasli
Copy link
Member

jiasli commented Apr 12, 2023

PS: I think az upgrade causes more issues than it resolves.

  • It does not check if new version is available in that distro. CentOS 7 users still see new version available.
  • Make __main__.py complicated.
  • Upgrade introduces many issues, but we can't address them. Upgrade failure may occur due to various reasons. For example: missing source.list file in DEB or permission error when install MSI.

Can't agree more.

get_cached_latest_versions()
from packaging.version import parse
if parse(VERSIONS['versions']['core']['local']) < parse(VERSIONS['versions']['core']['pypi']): # pylint: disable=line-too-long
if 'pypi' in VERSIONS['versions']['core'] and parse(VERSIONS['versions']['core']['local']) < parse(VERSIONS['versions']['core']['pypi']): # pylint: disable=line-too-long
Copy link
Member

@jiasli jiasli Apr 12, 2023

Choose a reason for hiding this comment

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

I think we should fix the invalid ~/.azure/versionCheck.json, instead of here, since it is the file that introduces inconsistency and complexity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is refreshed after 11 days, so I'd like to leave it there.

Skipping it or setting a dummy value for pypi produces the same result. I don't want to make the logic more complicate.

@jiasli jiasli assigned bebound and unassigned jiasli May 19, 2023
@bebound bebound changed the title {Core} Fix KeyError: 'pypi' when auto upgrade {Upgrade} Fix KeyError: 'pypi' when auto upgrade Apr 21, 2025
@bebound
Copy link
Contributor Author

bebound commented Apr 21, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jiasli
Copy link
Member

jiasli commented Apr 21, 2025

Approving in 2025. Looking at my comments, they seem to be from my past life.

@azure-client-tools-bot-prd
Copy link

️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

@bebound bebound merged commit 82a85fb into Azure:dev Apr 21, 2025
53 checks passed
@bebound bebound deleted the fix-pypi branch April 21, 2025 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot Core CLI core infrastructure Installation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Az Cli Message Auto upgrade failed. 'pypi' display despite running latest version

3 participants