You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Global Arguments stop working in Python 3.9.8 #20269
Global Arguments now stop working in Python 3.9.8:
> az cloud show --query profile
{
"endpoints": {
"activeDirectory": "https://login.microsoftonline.com",
...
Notice --query doesn't take effact.
Root cause
This is due to the argparse breaking change python/cpython#28420 which aims to solve https://bugs.python.org/issue45235. Python 3.9.8 is the first released version with this change. It will spread to all Python versions later.
In Knack, global arguments are registered on all root/intermediate/leaf parsers, and they share the same dest. Previously, leaf-level arguments takes precedence. After this change, root-level arguments take precedence.
We are not sure if this is intended or not, as according to Semantic Versioning, a PATCH version update shouldn't cause breaking change.
Since Azure CLI does some trimming on the command table, using --query on the root parser won't work. We have to use Knack directly to demonstrate it:
command
3.9.7
3.9.8
python .\knack\examples\exapp2 sample-json --query id
✔
❌
python .\knack\examples\exapp2 --query id sample-json
❌
✔
Proposed solution
Knack should only register global arguments on leaf parsers to avoid this issue. We don't allow using global arguments in the middle of a command anyway:
✔ az cloud show --query profile
❌ az --query profile cloud show
❌ az cloud --query profile show
References
This issue is also affecting other CLI tools utilizing argparse:
Łukasz Langa (@ambv), can we get an ETA for the Python 3.9.9 release with the fix? We are seeing Python 3.9.8 deployed to Azure Pipelines and MacOS Homebrew (#20322), which is affecting more and more users. Really appreciate your help.
As it is not easy to install old/specific versions of Python (like 3.9.7) on MacOS with brew (Homebrew/discussions#155), we are working with brew team to release Azure CLI on Python 3.10 as soon as possible which is not affected (Homebrew/homebrew-core#86758).
For now, as a workaround, you may manually install Python 3.10 and install azure-cli with
When using --subscription argument, you will see error
File "C:\Users\jiasli\AppData\Local\Programs\Python\Python39\lib\argparse.py", line 1932, in take_action
action(self, namespace, argument_values, option_string)
File "d:\cli\azure-cli\src\azure-cli-core\azure\cli\core\commands\arm.py", line 357, in __call__
profile = Profile(cli_ctx=namespace._cmd.cli_ctx) # pylint: disable=protected-access
AttributeError: 'Namespace' object has no attribute '_cmd'
This is due to the behavior change of default value discussed in python/cpython#28420 (comment) - default value is no longer set before the Action logic fires in self._parse_known_args.
~ % az --version
azure-cli 2.30.0
core 2.30.0
telemetry 1.0.6
Python location '/usr/local/Cellar/azure-cli/2.30.0_1/libexec/bin/python'
Extensions directory '/Users/xxxxxx/.azure/cliextensions'
Python (Darwin) 3.10.0 (default, Oct 13 2021, 06:45:00) [Clang 13.0.0 (clang-1300.0.29.3)]
Legal docs and information: aka.ms/AzureCliLegal
Your CLI is up-to-date.
however
~ % az aks list -o table
Table output unavailable. Use the --query option to specify an appropriate query. Use --debug for more info.
still looks broken to me. This used to work. What am I doing wrong? I get the same result if I include a query like in the example:
~ % az aks list --query "[].{resource:resourceGroup, name:name}" -o table
Table output unavailable. Use the --query option to specify an appropriate query. Use --debug for more info.
Table output unavailable. Use the --query option to specify an appropriate query. Use --debug for more info.
Looks similar to #20125. Though no Python version presented in that issue.
I came across the same problem when running az vm list.
This probably relates to python 3.10, cause this function normally on debian 10 with az 2.30.0 and python 3.6.10.
How should we test it?
Will it show up as a new version of az cli that can be upgraded via az upgrade?
Or is it merged to master and we should pull latest dev version?
thanks Łukasz Langa (@ambv) .
It looks like azure cli released a fix to hombrew as version 2.30.0_1 which now depends on python@3.10.
doing a brew update, brew upgrade fixed the issue for me.
Thanks for fixing as all my scripts were breaking before!
Crayeth, tuzi3040 (@tuzi3040), for the Table output unavailable. Use the --query option to specify an appropriate query. Use --debug for more info. issue , let's work on #20348.
⚠ You may also use Python 3.10 to install Azure CLI, but be aware that --output table won't function correctly (#20348). It will be fixed in Azure CLI 2.31.0.
Activity
gvanrossum commentedon Nov 10, 2021
Raymond Hettinger (@rhettinger) Łukasz Langa (@ambv) Can you look at this? It looks like a serious regression in 3.9.8.
jiasli commentedon Nov 12, 2021
Thank you so much Guido van Rossum (@gvanrossum) for the prompt response and fix! Really appreciate your help!
jiasli commentedon Nov 12, 2021
For our own tracking purposes:
mainbranch: bpo-45235: Revert an argparse bugfix that caused a regression python/cpython#29525python:3.9: [3.9] bpo-45235: Revert an argparse bugfix that caused a regression (GH-29525) python/cpython#29531jiasli commentedon Nov 15, 2021
Łukasz Langa (@ambv), can we get an ETA for the Python 3.9.9 release with the fix? We are seeing Python 3.9.8 deployed to Azure Pipelines and MacOS Homebrew (#20322), which is affecting more and more users. Really appreciate your help.
jiasli commentedon Nov 15, 2021
For MacOS users:
As it is not easy to install old/specific versions of Python (like 3.9.7) on MacOS with brew (Homebrew/discussions#155), we are working with brew team to release Azure CLI on Python 3.10 as soon as possible which is not affected (Homebrew/homebrew-core#86758).
For now, as a workaround, you may manually install Python 3.10 and install
azure-cliwithjiasli commentedon Nov 15, 2021
When using
--subscriptionargument, you will see errorThis is due to the behavior change of default value discussed in python/cpython#28420 (comment) - default value is no longer set before the
Actionlogic fires inself._parse_known_args.ambv commentedon Nov 15, 2021
Crayeth commentedon Nov 15, 2021
however
still looks broken to me. This used to work. What am I doing wrong? I get the same result if I include a query like in the example:
tuzi3040 commentedon Nov 15, 2021
Looks similar to #20125. Though no Python version presented in that issue.
I came across the same problem when running
az vm list.This probably relates to python 3.10, cause this function normally on debian 10 with az 2.30.0 and python 3.6.10.
May be better to open another issue.
Karrade7 commentedon Nov 15, 2021
How should we test it?
Will it show up as a new version of az cli that can be upgraded via az upgrade?
Or is it merged to master and we should pull latest dev version?
Thanks!
ambv commentedon Nov 15, 2021
Sorry, I'm releasing Python 3.9.9 today, not azure-cli. The fixed Python 3.9.9 release is now available:
https://www.python.org/downloads/release/python-399/
Karrade7 commentedon Nov 15, 2021
thanks Łukasz Langa (@ambv) .
It looks like azure cli released a fix to hombrew as version 2.30.0_1 which now depends on python@3.10.
doing a brew update, brew upgrade fixed the issue for me.
Thanks for fixing as all my scripts were breaking before!
yonzhan commentedon Nov 15, 2021
Thanks Łukasz Langa (@ambv), good to know you have released Python 3.9.9
jiasli commentedon Nov 16, 2021
Crayeth, tuzi3040 (@tuzi3040), for the
Table output unavailable. Use the --query option to specify an appropriate query. Use --debug for more info.issue , let's work on #20348.jiasli commentedon Nov 16, 2021
Solution
If you directly use Python
As Python 3.9.9 has been released, please download and install the latest Python 3.9.9 from https://www.python.org/downloads/.
⚠ You may also use Python 3.10 to install Azure CLI, but be aware that
--output tablewon't function correctly (#20348). It will be fixed in Azure CLI 2.31.0.If you use Homebrew on MacOS
Homebrew/homebrew-core#86758 has been merged. Please update Azure CLI installation with
⚠ As now the formula uses Python 3.10,
--output tablewon't function correctly (#20348). It will be fixed in Azure CLI 2.31.0.