Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tabulate failure: ImportError: cannot import name 'Iterable' from 'collections' #20348

Closed
jiasli opened this issue Nov 16, 2021 · 8 comments
Closed
Assignees
Labels
Core CLI core infrastructure

Comments

@jiasli
Copy link
Member

jiasli commented Nov 16, 2021

~ % 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.

Originally posted by @Crayeth in #20269 (comment)

@ghost ghost added the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Nov 16, 2021
@jiasli
Copy link
Member Author

jiasli commented Nov 16, 2021

As shown in #20125 (comment), --debug log will show the call stack:

cli.knack.cli: Event: CommandInvoker.OnTransformResult [<function _resource_group_transform at 0x1031b1f30>, <function _x509_from_base64_to_hex_transform at 0x1031b1fc0>]
cli.knack.cli: Event: CommandInvoker.OnFilterResult []
cli.knack.output: Traceback (most recent call last):
  File "/opt/homebrew/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/knack/output.py", line 76, in format_table
    return to.dump(result_list)
  File "/opt/homebrew/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/knack/output.py", line 207, in dump
    from tabulate import tabulate
  File "/opt/homebrew/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/tabulate.py", line 16, in <module>
    from collections import Iterable
ImportError: cannot import name 'Iterable' from 'collections' (/opt/homebrew/Cellar/[email protected]/3.10.0_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/collections/__init__.py)

cli.azure.cli.core.util: azure.cli.core.util.handle_exception is called with an exception:
cli.azure.cli.core.util: Traceback (most recent call last):
  File "/opt/homebrew/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/knack/output.py", line 76, in format_table
    return to.dump(result_list)
  File "/opt/homebrew/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/knack/output.py", line 207, in dump
    from tabulate import tabulate
  File "/opt/homebrew/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/tabulate.py", line 16, in <module>
    from collections import Iterable
ImportError: cannot import name 'Iterable' from 'collections' (/opt/homebrew/Cellar/[email protected]/3.10.0_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/collections/__init__.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/knack/cli.py", line 237, in invoke
    self.output.out(cmd_result, formatter=formatter, out_file=out_file)
  File "/opt/homebrew/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/knack/output.py", line 146, in out
    output = formatter(obj)
  File "/opt/homebrew/Cellar/azure-cli/2.30.0_1/libexec/lib/python3.10/site-packages/knack/output.py", line 79, in format_table
    raise CLIError("Table output unavailable. "
knack.util.CLIError: Table output unavailable. Use the --query option to specify an appropriate query. Use --debug for more info.

cli.azure.cli.core.azclierror: Table output unavailable. Use the --query option to specify an appropriate query. Use --debug for more info.
az_command_data_logger: Table output unavailable. Use the --query option to specify an appropriate query. Use --debug for more info.
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x103166560>]
cli.__main__: Command ran in 0.798 seconds (init: 0.045, invoke: 0.753)

This is due to a bug of tabulate where it used string to compare version, resulting in "10" < "3", which is certainly wrong. This bug has been fixed by astanin/python-tabulate#105.

Azure CLI has bumped tabulate to the latest version (#20195 (comment)) and the fix will be released in 2.31.0.

The reason why we rushed the Python 3.10 onboarding (Homebrew/homebrew-core#86758) (even though it is not fully compatible with Azure CLI due to this tabulate issue) is due to the malfunctioning of global arguments caused by Python 3.9.8 regression (#20269). Even though --output table is still not working, at least --output json, --output tsv, --query, etc are back to normal.

@yonzhan yonzhan added the Core CLI core infrastructure label Nov 16, 2021
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Nov 16, 2021
@yonzhan yonzhan added this to the Backlog milestone Nov 16, 2021
@jiasli jiasli modified the milestones: Backlog, Nov 2021 (2021-12-07) Nov 16, 2021
@alsastre
Copy link

Please, consider publishing sooner 2.31 or removing 2.30 as this problem is making some commands of the az cli not usable.
See: #20362 #20348 #20343

@jiasli
Copy link
Member Author

jiasli commented Nov 19, 2021

@alsastre, According to https://formulae.brew.sh/formula/[email protected], Homebrew hasn't take the latest Python 3.9.9 yet which has https://bugs.python.org/issue45235 fixed:

image

After that, this issue could have been easily resolved by installing a previous version of Azure CLI, BUT it is difficult to install a previous version with Homebrew. Homebrew also discourages installing previous versions. See Homebrew/discussions#155.

Our release schedule is fixed and Azure CLI 2.31.0 will be released on 2021-12-07.

If you really need to use --output table, after Python 3.9.9 is taken by Homebrew, you may consider installing previous Azure CLI 2.29.2 following some workarounds:

@jiasli
Copy link
Member Author

jiasli commented Nov 24, 2021

Homebrew has now released Python 3.9.9 (https://formulae.brew.sh/formula/[email protected]). As a workaround, you may install Python 3.9.9 first and then install Azure CLI with pip:

# Uninstall Azure CLI installed by brew
brew uninstall azure-cli

# Uninstall Python 3.10 first if you have it
brew uninstall [email protected]

# Install Python 3.9
brew install [email protected]

# Install the latest Azure CLI from PyPI
pip3 install azure-cli

@jamesongithub
Copy link

looks like fix is in 2.31.0 slated for 2021.12.07 release?

@jiasli jiasli changed the title Table output unavailable. Use the --query option to specify an appropriate query. Use --debug for more info. tabulate failure: ImportError: cannot import name 'Iterable' from 'collections' Nov 24, 2021
@ringoc
Copy link

ringoc commented Nov 25, 2021

Homebrew has now released Python 3.9.9 (https://formulae.brew.sh/formula/[email protected]). As a workaround, you may install Python 3.9.9 first and then install Azure CLI with pip:

# Uninstall Azure CLI installed by brew
brew uninstall azure-cli

# Uninstall Python 3.10 first if you have it
brew uninstall [email protected]

# Install Python 3.9
brew install [email protected]

# Install the latest Azure CLI from PyPI
pip3 install azure-cli

I confirmed this workaround is working perfectly

@ilhaan
Copy link
Member

ilhaan commented Dec 7, 2021

Azure-CLI 2.31.0 was released today: https://github.com/Azure/azure-cli/releases/tag/azure-cli-2.31.0. I upgraded to 2.31.0 and no longer see the Table output unavailable error.

@jiasli
Copy link
Member Author

jiasli commented Dec 8, 2021

Thanks @ilhaan for the confirmation. Yes, Azure CLI 2.31.0 was released by Homebrew/homebrew-core#90628. This issue should now be fixed.

Please update Azure CLI to the latest version 2.31.0:

brew update && brew upgrade azure-cli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core CLI core infrastructure
Projects
None yet
Development

No branches or pull requests

6 participants