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

CLI Blob list checking contentLength crashes #29645

Closed
jmalbarran opened this issue Aug 3, 2024 · 4 comments
Closed

CLI Blob list checking contentLength crashes #29645

jmalbarran opened this issue Aug 3, 2024 · 4 comments
Assignees
Labels
Auto-Assign Auto assign by bot Azure CLI Team The command of the issue is owned by Azure CLI team customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Storage az storage
Milestone

Comments

@jmalbarran
Copy link

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

@jmalbarran jmalbarran added the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Aug 3, 2024
@yonzhan
Copy link
Collaborator

yonzhan commented Aug 3, 2024

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

@microsoft-github-policy-service microsoft-github-policy-service bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. Storage az storage labels Aug 3, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added Auto-Assign Auto assign by bot Azure CLI Team The command of the issue is owned by Azure CLI team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Aug 3, 2024
@yonzhan yonzhan added this to the Backlog milestone Aug 3, 2024
@yonzhan yonzhan removed the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Aug 3, 2024
@calvinhzy
Copy link
Member

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

@jmalbarran
Copy link
Author

jmalbarran commented Aug 5, 2024 via email

@jmalbarran
Copy link
Author

jmalbarran commented Aug 5, 2024

I got an answer in StackOverflow.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Assign Auto assign by bot Azure CLI Team The command of the issue is owned by Azure CLI team customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Storage az storage
Projects
None yet
Development

No branches or pull requests

4 participants