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

az cli incorrect parsing of query "--query "[0].keys(@)" #14972

Closed
ralfkret opened this issue Aug 30, 2020 · 10 comments
Closed

az cli incorrect parsing of query "--query "[0].keys(@)" #14972

ralfkret opened this issue Aug 30, 2020 · 10 comments
Assignees
Labels
Core CLI core infrastructure customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention This issue is responsible by Azure service team. Shell - PowerShell

Comments

@ralfkret
Copy link

This is autogenerated. Please review and update as needed.

Describe the bug

I get an error message (see below) when I issue the following command. The command should output the structure of the json data.

Command Name
az vm list -d --query "[0].keys(@)"

Errors:

az vm list: error: argument --query: invalid jmespath_type value: '[0].keys(@'
usage: az vm list [-h] [--verbose] [--debug] [--only-show-errors]
                  [--output {json,jsonc,yaml,yamlc,table,tsv,none}]
                  [--query JMESPATH] [--subscription _SUBSCRIPTION]
                  [--resource-group RESOURCE_GROUP_NAME] [--show-details]
To learn more about [--query JMESPATH] usage in AzureCLI, visit https://aka.ms/CLIQuery

C:\>echo Failed to load python executable.
Failed to load python executable.

C:\>exit /b 1

As you may notice in the error message the closing parenthesis of the query is missing.
So I reissued the slightly modified command with an extra space after the closing parenthesis:

az vm list -d --query "[0].keys(@) "

Et Voilà:

[
  "location",
  "tags",
 ... skipped for prevety
 "privateIps",
  "macAddresses",
  "resourceGroup"
]

To Reproduce:

See above.

Expected Behavior

The command should output the keys of the json describing the vm.

Environment Summary

Windows-10-10.0.19041-SP0
Python 3.6.8
Installer: MSI

azure-cli 2.11.0 *

Extensions:
interactive 0.4.4

Additional Context

@ghost ghost added needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Aug 30, 2020
@yungezz yungezz added Compute az vm/vmss/image/disk/snapshot and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Aug 31, 2020
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Aug 31, 2020
@yungezz
Copy link
Member

yungezz commented Aug 31, 2020

thanks for reporting the issue! hi @qwordy could you pls help to have a look? Is this a general issue in query? thanks

@qwordy
Copy link
Member

qwordy commented Aug 31, 2020

Remove the compute label. --query is a global parameter.

@qwordy qwordy added Core CLI core infrastructure and removed Compute az vm/vmss/image/disk/snapshot labels Aug 31, 2020
@jiasli
Copy link
Member

jiasli commented Sep 7, 2020

I can't run this command and got error #15064. @qwordy

@jiasli jiasli self-assigned this Sep 7, 2020
@jiasli
Copy link
Member

jiasli commented Sep 7, 2020

It looks like you are running this command in Command Prompt, but I can't reproduce it

D:\cli>az vm list --query "[0].keys(@)"
[
  "location",
  "tags",
  "plan",
  ...
]

May I know what terminal you are using?

By the way, there are some known quoting issues with PowerShell.

But when I ran this command, it is weird that the command is actually invoked twice, one without the ) and one with ).

> az vm list --debug --query "[0].keys(@)"
Command arguments: ['vm', 'list', '--debug', '--query', '[0].keys(@']
...
az vm list: error: argument --query: invalid jmespath_type value: '[0].keys(@'
...
Command arguments: ['vm', 'list', '--debug', '--query', '[0].keys(@)']
...
[
  "id",
  "name",
  "type",
  "location",
...

I am not sure why this happens, but anyway in PowerShell the correct way to run this command is to quote @ twice, one for Command Prompt, one for PowerShell:

az vm list --query '"[0].keys(@)"'
# or
az --% vm list --query "[0].keys(@)"

@ralfkret
Copy link
Author

ralfkret commented Sep 7, 2020

Indeed I am using Powershell (version 5.1.19041.1 running in Windows Terminal 1.2.2381.0).
When I switch to Command.exe the original command az vm list --query "[0].keys(@)" works as expected.
I wasn't aware of the quoting issues you have mentioned

@ralfkret
Copy link
Author

ralfkret commented Sep 7, 2020

At least now I have an idea why the variant with the extra space az vm list --query "[0].keys(@) " worked.

I assumed any character would do, but the real difference seems to be that the whitespace prevents prevents PowerShell from stripping the quotes as mentioned in Quoting issues with PowerShell.

This is confirmed by the fact that the following variants of the command work as expected (in PowerShell):

az vm list --query " [0].keys(@)"
az vm list --query "[0].keys( @ )"

Well - live and learn.

@jiasli
Copy link
Member

jiasli commented Sep 7, 2020

Glad to know the issue is solved. 😊

@houk-ms, maybe we can improve the error message for --query to inform the user that they may be hitting Quoting issues with PowerShell?

@houk-ms
Copy link
Contributor

houk-ms commented Sep 7, 2020

sure, that make sense. while if it only happens on powershell, maybe better if we can show the hints only to powershell users

@qwordy
Copy link
Member

qwordy commented Sep 7, 2020

I can't run this command and got error #15064. @qwordy

It is a service issue after my investigation.

@azure-sdk azure-sdk added the customer-reported Issues that are reported by GitHub users external to the Azure organization. label Sep 24, 2020
@yonzhan yonzhan added the Service Attention This issue is responsible by Azure service team. label Dec 7, 2020
@jiasli
Copy link
Member

jiasli commented Mar 1, 2024

Tracked by #15529

@jiasli jiasli closed this as completed Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core CLI core infrastructure customer-reported Issues that are reported by GitHub users external to the Azure organization. Service Attention This issue is responsible by Azure service team. Shell - PowerShell
Projects
None yet
Development

No branches or pull requests

7 participants