Skip to content

Conversation

@fengzhou-msft
Copy link
Member

@fengzhou-msft fengzhou-msft commented Mar 16, 2021

Description

Resolve #16952

The issue was caused by reloading the azure.cli.core python module to get the new version after upgrade, it depends on modules in knack. The new loaded azure.cli.core depends on new code of a new knack version: from knack.util import status_tag_messages, but knack.util is not reloaded, causing the issue of ImportError.

There are two ways to solve this issue:

  1. Reload all loaded modules in sys.modules starting with knack such as knack.util, knack.log. Note that knack and knack.util are 2 items in sys.modules, simply reloading knack will not fix the ImportError with from knack.util import status_tag_messages.
  2. Use subprocess to get az version to avoid calling cached modules in the same Python Interpreter.

This PR uses the second method as it is more error-proofing and easier to maintain as azure.cli.core could rely on new modules in the future.

Testing Guide

  1. Create a clean virtual env and activate it
    python -m venv env-test
  2. Install the old version of azure-cli
    pip install azure-cli==2.17.1
  3. Modify this file to apply changes in this PR:
    env-test/lib/site-packages/azure/cli/command_modules/util/custom.py
  4. Run az upgrade

History Notes

[Component Name 1] BREAKING CHANGE: az command a: Make some customer-facing breaking change.
[Component Name 2] az command b: Add some customer-facing feature.


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

Copy link
Member

@jiasli jiasli left a comment

Choose a reason for hiding this comment

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

Elegant solution!

@fengzhou-msft fengzhou-msft merged commit bed4963 into Azure:dev Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

az upgrade from 2.17.1 to 2.19.1 fails with cannot import name 'status_tag_messages'

2 participants