Azure / azure-cli

Azure Command-Line Interface
MIT License
3.96k stars 2.94k forks source link

CLI Blob list checking contentLength crashes #29645

Closed jmalbarran closed 1 month ago

jmalbarran commented 1 month ago

Describe the bug

I'm trying to select all the blobs with content (basically, to avoid directories).

I'm trying the following query:

az storage blob list --account-name myaccount --account-key myaccountkey --container-name mycontainer --prefix myprefix --query "[?properties.contentLength > '0'].name" --num-results "*" --output tsv|more

Azure CLI crashes with the following error:

TypeError: '>' not supported between instances of 'int' and 'str'

The full trace is:

Traceback (most recent call last):
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 676, in execute
    self.cli_ctx.raise_event(EVENT_INVOKER_FILTER_RESULT, event_data=event_data)
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/knack/cli.py", line 170, in raise_event
    func(self, **kwargs)
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/knack/query.py", line 45, in filter_output
    kwargs['event_data']['result'] = query_expression.search(
                                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/jmespath/parser.py", line 509, in search
    result = interpreter.visit(self.parsed, value)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/jmespath/visitor.py", line 94, in visit
    return method(node, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/jmespath/visitor.py", line 180, in visit_filter_projection
    if self._is_true(self.visit(comparator_node, element)):
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/jmespath/visitor.py", line 94, in visit
    return method(node, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/jmespath/visitor.py", line 158, in visit_comparator
    return comparator_func(left, right)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '>' not supported between instances of 'int' and 'str'

Related command

I'm trying to select all the blobs with content (basically, to avoid directories).

I'm trying the following query:

az storage blob list --account-name myaccount --account-key myaccountkey --container-name mycontainer --prefix myprefix --query "[?properties.contentLength > '0'].name" --num-results "*" --output tsv|more

Errors

I'm trying to select all the blobs with content (basically, to avoid directories). Azure CLI crashes with the following error:

TypeError: '>' not supported between instances of 'int' and 'str'

The full trace is:

Traceback (most recent call last):
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 676, in execute
    self.cli_ctx.raise_event(EVENT_INVOKER_FILTER_RESULT, event_data=event_data)
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/knack/cli.py", line 170, in raise_event
    func(self, **kwargs)
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/knack/query.py", line 45, in filter_output
    kwargs['event_data']['result'] = query_expression.search(
                                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/jmespath/parser.py", line 509, in search
    result = interpreter.visit(self.parsed, value)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/jmespath/visitor.py", line 94, in visit
    return method(node, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/jmespath/visitor.py", line 180, in visit_filter_projection
    if self._is_true(self.visit(comparator_node, element)):
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/jmespath/visitor.py", line 94, in visit
    return method(node, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/jmespath/visitor.py", line 158, in visit_comparator
    return comparator_func(left, right)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '>' not supported between instances of 'int' and 'str'

Issue script & Debug output

I'm trying to select all the blobs with content (basically, to avoid directories).

I'm trying the following query:

az storage blob list --account-name myaccount --account-key myaccountkey --container-name mycontainer --prefix myprefix --query "[?properties.contentLength > '0'].name" --num-results "*" --output tsv|more

Azure CLI crashes with the following error:

TypeError: '>' not supported between instances of 'int' and 'str'

The full trace is:

Traceback (most recent call last):
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/azure/cli/core/commands/__init__.py", line 676, in execute
    self.cli_ctx.raise_event(EVENT_INVOKER_FILTER_RESULT, event_data=event_data)
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/knack/cli.py", line 170, in raise_event
    func(self, **kwargs)
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/knack/query.py", line 45, in filter_output
    kwargs['event_data']['result'] = query_expression.search(
                                     ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/jmespath/parser.py", line 509, in search
    result = interpreter.visit(self.parsed, value)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/jmespath/visitor.py", line 94, in visit
    return method(node, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/jmespath/visitor.py", line 180, in visit_filter_projection
    if self._is_true(self.visit(comparator_node, element)):
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/jmespath/visitor.py", line 94, in visit
    return method(node, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/azure-cli/2.62.0/libexec/lib/python3.11/site-packages/jmespath/visitor.py", line 158, in visit_comparator
    return comparator_func(left, right)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '>' not supported between instances of 'int' and 'str'

Expected behavior

Return of all objects with size greater than 0 (avoid subdirectories)

Environment Summary

azure-cli 2.62.0

core 2.62.0 telemetry 1.1.0

Dependencies: msal 1.28.1 azure-mgmt-resource 23.1.1

Python location '/usr/local/Cellar/azure-cli/2.62.0/libexec/bin/python' Extensions directory '/Users/jmalbarran/.azure/cliextensions'

Python (Darwin) 3.11.9 (main, Apr 2 2024, 08:25:04) [Clang 15.0.0 (clang-1500.3.9.4)]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

Additional context

No response

yonzhan commented 1 month ago

Thank you for opening this issue, we will look into it.

calvinhzy commented 1 month ago

@jmalbarran can you try --query "[?properties.contentLength > 0].name"

jmalbarran commented 1 month ago

Already did! It crashes with different error. Checked with JMSPath sintax, and it seems than event with number content, you have to quote the parameter.

Enviado desde Outlook para Androidhttps://aka.ms/AAb9ysg


From: Zhiyi Huang @.> Sent: Monday, August 5, 2024 5:23:46 AM To: Azure/azure-cli @.> Cc: Jose Manuel Albarrán @.>; Mention @.> Subject: Re: [Azure/azure-cli] CLI Blob list checking contentLength crashes (Issue #29645)

@jmalbarranhttps://github.com/jmalbarran can you try --query "[?properties.contentLength > 0].name"

— Reply to this email directly, view it on GitHubhttps://github.com/Azure/azure-cli/issues/29645#issuecomment-2268098663, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AT3JLNLLH464T5ZREMVOTA3ZP3V4FAVCNFSM6AAAAABL6BF3H2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENRYGA4TQNRWGM. You are receiving this because you were mentioned.Message ID: @.***>

jmalbarran commented 1 month ago

I got an answer in StackOverflow.

This is the solution --query "[?properties.contentLength > `0`].name"