Azure / azure-cli

Azure Command-Line Interface
MIT License
4.02k stars 3k forks source link

Fails to remove `ml` extension on Windows #24390

Open bebound opened 2 years ago

bebound commented 2 years ago

This is autogenerated. Please review and update as needed.

Describe the bug

When remove ml extension, pvectorc.cp310-win32.pyd file can't be deleted.

After this command fails, az extension list raises error:

  File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/extension/__init__.py", line 308, in get_extension_modname
AssertionError: Expected 1 module to load starting with 'azext_': got []

After some investigation, I think pyrsistent might be the reason. Create a new virtual env and install pyrsistent. This script also fails with same error:

import os

import pyrsistent
os.remove('venv/Lib/site-packages/pvectorc.cp310-win_amd64.pyd')

Once pyrsistent is imported, this file can't be deleted. I guess the file is opened by Python, but I can't find a way to release it.


In ml extension, pyrsistent is imported by jsonschema, and jsonschema is used in azext_mlv2\manual\vendored_curated_sdk\azure\ai\ml\_utils\_data_utils.py:

from jsonschema import Draft7Validator, ValidationError
from jsonschema.exceptions import best_match

If these two lines are not executed when cli load ml extension, the issue could be fixed.

Workaround

Manually delete C:\Users\hanglei\.azure\cliextensions/ml folder to remove extension.

Command Name az extension remove

Errors:

Failed to delete 'C:\Users\kk\.azure\cliextensions\ml': [WinError 5] Access is denied: 'C:\\Users\\kk\\.azure\\cliextensions\\ml\\pvectorc.cp310-win32.pyd'. Retrying ...
Failed to delete 'C:\Users\kk\.azure\cliextensions\ml': [WinError 5] Access is denied: 'C:\\Users\\kk\\.azure\\cliextensions\\ml\\pvectorc.cp310-win32.pyd'. Retrying ...
Failed to delete 'C:\Users\kk\.azure\cliextensions\ml': [WinError 5] Access is denied: 'C:\\Users\\kk\\.azure\\cliextensions\\ml\\pvectorc.cp310-win32.pyd'. Retrying ...
Failed to delete 'C:\Users\kk\.azure\cliextensions\ml': [WinError 5] Access is denied: 'C:\\Users\\kk\\.azure\\cliextensions\\ml\\pvectorc.cp310-win32.pyd'. You may try to delete it manually.

To Reproduce:

az extension add -n ml
az extension remove -n ml

Expected Behavior

Environment Summary

Windows-10-10.0.22621-SP0
Python 3.10.5
Installer: MSI

azure-cli 2.41.0

Extensions:
account 0.2.5
alias 0.5.2
interactive 0.4.5
ml Unknown
rdbms-connect 1.0.3

Dependencies:
msal 1.20.0b1
azure-mgmt-resource 21.1.0b1

Additional Context

ghost commented 2 years ago

Thank you for your feedback. This has been routed to the support team for assistance.

yonzhan commented 2 years ago

Good finding!