azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

storage blob download-batch with glob pattern fails in v2.77

Open danielpof opened this issue 1 year ago • 28 comments

Describe the bug

When attempting to download-batch from blob storage with a glob pattern an error occurs in v2.77. If downloading a single file (no glob) there's no error, or when using a previous version with glob it also works

Related command

az storage blob download-batch -s files --pattern 'path/*' --account-name staccount --auth-mode key -d .

Errors

The command failed with an unexpected error. Here is the traceback:
cannot use a string pattern on a bytes-like object
Traceback (most recent call last):
  File "/opt/az/lib/python3.13/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 666, in execute
    raise ex
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 734, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_job
    return cmd_copy.exception_handler(ex)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/__init__.py", line 358, in new_handler
    first(ex)
    ~~~~~^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/__init__.py", line 358, in new_handler
    first(ex)
    ~~~~~^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/_exception_handler.py", line 17, in file_related_exception_handler
    raise ex
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 703, in _run_job
    result = cmd_copy(params)
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 336, in __call__
    return self.handler(*args, **kwargs)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/command_operation.py", line 120, in handler
    return op(**command_args)
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/operations/blob.py", line 417, in storage_blob_download_batch
    source_blobs = collect_blobs(client, source_container_name, pattern)
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/util.py", line 16, in collect_blobs
    return [name for (name, _) in collect_blob_objects(blob_service, container, pattern)]
                                  ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/util.py", line 52, in collect_blob_objects
    if not pattern or _match_path(blob_name, pattern):
                      ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/util.py", line 199, in _match_path
    return fnmatch(path, pattern)
  File "/opt/az/lib/python3.13/fnmatch.py", line 36, in fnmatch
    return fnmatchcase(name, pat)
  File "/opt/az/lib/python3.13/fnmatch.py", line 71, in fnmatchcase
    return match(name) is not None
           ~~~~~^^^^^^
TypeError: cannot use a string pattern on a bytes-like object

Issue script & Debug output

urllib3.connectionpool: https://staccount.blob.core.windows.net:443 "GET /files?restype=container&comp=list&prefix=path%2F HTTP/1.1" 200 None
cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "/opt/az/lib/python3.13/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 666, in execute
    raise ex
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 734, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_job
    return cmd_copy.exception_handler(ex)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/__init__.py", line 358, in new_handler
    first(ex)
    ~~~~~^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/__init__.py", line 358, in new_handler
    first(ex)
    ~~~~~^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/_exception_handler.py", line 17, in file_related_exception_handler
    raise ex
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 703, in _run_job
    result = cmd_copy(params)
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 336, in __call__
    return self.handler(*args, **kwargs)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/command_operation.py", line 120, in handler
    return op(**command_args)
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/operations/blob.py", line 417, in storage_blob_download_batch
    source_blobs = collect_blobs(client, source_container_name, pattern)
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/util.py", line 16, in collect_blobs
    return [name for (name, _) in collect_blob_objects(blob_service, container, pattern)]
                                  ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/util.py", line 52, in collect_blob_objects
    if not pattern or _match_path(blob_name, pattern):
                      ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/util.py", line 199, in _match_path
    return fnmatch(path, pattern)
  File "/opt/az/lib/python3.13/fnmatch.py", line 36, in fnmatch
    return fnmatchcase(name, pat)
  File "/opt/az/lib/python3.13/fnmatch.py", line 71, in fnmatchcase
    return match(name) is not None
           ~~~~~^^^^^^
TypeError: cannot use a string pattern on a bytes-like object

cli.azure.cli.core.azclierror: The command failed with an unexpected error. Here is the traceback:
az_command_data_logger: The command failed with an unexpected error. Here is the traceback:
cli.azure.cli.core.azclierror: cannot use a string pattern on a bytes-like object
Traceback (most recent call last):
  File "/opt/az/lib/python3.13/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 666, in execute
    raise ex
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 734, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_job
    return cmd_copy.exception_handler(ex)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/__init__.py", line 358, in new_handler
    first(ex)
    ~~~~~^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/__init__.py", line 358, in new_handler
    first(ex)
    ~~~~~^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/_exception_handler.py", line 17, in file_related_exception_handler
    raise ex
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 703, in _run_job
    result = cmd_copy(params)
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 336, in __call__
    return self.handler(*args, **kwargs)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/command_operation.py", line 120, in handler
    return op(**command_args)
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/operations/blob.py", line 417, in storage_blob_download_batch
    source_blobs = collect_blobs(client, source_container_name, pattern)
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/util.py", line 16, in collect_blobs
    return [name for (name, _) in collect_blob_objects(blob_service, container, pattern)]
                                  ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/util.py", line 52, in collect_blob_objects
    if not pattern or _match_path(blob_name, pattern):
                      ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/util.py", line 199, in _match_path
    return fnmatch(path, pattern)
  File "/opt/az/lib/python3.13/fnmatch.py", line 36, in fnmatch
    return fnmatchcase(name, pat)
  File "/opt/az/lib/python3.13/fnmatch.py", line 71, in fnmatchcase
    return match(name) is not None
           ~~~~~^^^^^^
TypeError: cannot use a string pattern on a bytes-like object
az_command_data_logger: cannot use a string pattern on a bytes-like object
Traceback (most recent call last):
  File "/opt/az/lib/python3.13/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 666, in execute
    raise ex
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 734, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_job
    return cmd_copy.exception_handler(ex)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/__init__.py", line 358, in new_handler
    first(ex)
    ~~~~~^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/__init__.py", line 358, in new_handler
    first(ex)
    ~~~~~^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/_exception_handler.py", line 17, in file_related_exception_handler
    raise ex
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 703, in _run_job
    result = cmd_copy(params)
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/__init__.py", line 336, in __call__
    return self.handler(*args, **kwargs)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/core/commands/command_operation.py", line 120, in handler
    return op(**command_args)
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/operations/blob.py", line 417, in storage_blob_download_batch
    source_blobs = collect_blobs(client, source_container_name, pattern)
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/util.py", line 16, in collect_blobs
    return [name for (name, _) in collect_blob_objects(blob_service, container, pattern)]
                                  ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/util.py", line 52, in collect_blob_objects
    if not pattern or _match_path(blob_name, pattern):
                      ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.13/site-packages/azure/cli/command_modules/storage/util.py", line 199, in _match_path
    return fnmatch(path, pattern)
  File "/opt/az/lib/python3.13/fnmatch.py", line 36, in fnmatch
    return fnmatchcase(name, pat)
  File "/opt/az/lib/python3.13/fnmatch.py", line 71, in fnmatchcase
    return match(name) is not None
           ~~~~~^^^^^^
TypeError: cannot use a string pattern on a bytes-like object
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues

Expected behavior

Files to be downloaded correctly like in v2.76

Environment Summary

azure-cli 2.77.0

core 2.77.0 telemetry 1.1.0

Extensions: account 0.2.5 appservice-kube 0.1.9 azure-devops 1.0.2 bastion 0.3.0 connectedmachine 1.0.0b2 front-door 1.0.16 import-export 0.1.1 managementpartner 0.1.3 providerhub 1.0.0b2 resource-graph 2.1.0 ssh 1.0.0

Dependencies: msal 1.34.0b1 azure-mgmt-resource 23.3.0

Additional context

Also happens in container version, previous versions have no issue

danielpof avatar Sep 02 '25 08:09 danielpof

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

yonzhan avatar Sep 02 '25 08:09 yonzhan

Also seeing this issue, definitely a regression bug not a question

will-tatam-tt avatar Sep 03 '25 10:09 will-tatam-tt

I can confirm this issue on Ubuntu 24.04.03, AlmaLinux 9.6 and AlmaLinux 10.0, Debian 11.11, just command "az storage blob download-batch --source https://xxx.blob.core.windows.net/scripts --destination ." fails on all of those after update from 2.76.0 to 2.77.0 and it worked before and downgrade fixes issue on all platforms.

raatti avatar Sep 03 '25 10:09 raatti

yes its also failing for me when trying the command with --pattern throws error TypeError: cannot use a string pattern on a bytes-like object but downgrading the az cli version to 2.76.0 works fine. Unfortunately the curl url which is used to download the az cli only downloads the latest version always curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

Is there any url that we can use to download the InstallAzureCLIDeb file for version 2.76.0 ?

anumukovTR avatar Sep 03 '25 12:09 anumukovTR

@anumukovTR https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-linux?view=azure-cli-latest&pivots=apt#install-specific-version Can you add another line to install the specific version sudo apt-get install azure-cli=${AZ_VER}-1~${AZ_DIST} Looking into the issue. Image

calvinhzy avatar Sep 04 '25 03:09 calvinhzy

Also affecting the AzureCLI@1 DevOps task, which apparently updated to v.2.77 yesterday. Broke our nightly deployment pipeline. So +1 for fixing this asap.

==============================================================================
Task         : Azure CLI
Description  : Run Azure CLI commands against an Azure subscription in a Shell script when running on Linux agent or Batch script when running on Windows agent.
Version      : 1.247.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-cli
==============================================================================
C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" --version"
azure-cli                         2.77.0

johtela avatar Sep 09 '25 06:09 johtela

Also Affecting AzureCli@2 DevOps task, as it was also updated to v2.77 yesterday

==============================================================================
Task         : Azure CLI
Description  : Run Azure CLI commands against an Azure subscription in a PowerShell Core/Shell script when running on Linux agent or PowerShell/PowerShell Core/Batch script when running on Windows agent.
Version      : 2.259.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-cli
==============================================================================
/usr/bin/az --version
azure-cli                         2.77.0

krogne avatar Sep 09 '25 07:09 krogne

Confirming that starting today it is affecting AzureCli@2 task on Azure DevOps. All of pipelines are stuck.

Our temporary fix was adding this step to downgrade azure-cli before the task.

Image

mmatteo01 avatar Sep 09 '25 08:09 mmatteo01

This needs to be fixed ASAP. We now have a broken pipeline that's used for business critical tasks. Please merge the PR and release 2.78.0 without delay.

rybon avatar Sep 09 '25 12:09 rybon

same here

cyptus avatar Sep 09 '25 13:09 cyptus

Same issue happening for many people at my company as well.

matthew-sutterlin avatar Sep 09 '25 15:09 matthew-sutterlin

GitHub actions temporary fix to add before the blob storage steps.

     - name: 'Pin Azure CLI to 2.76.0' # Can be removed this issue is fixed. https://github.com/Azure/azure-cli/issues/32039
        run: |
          sudo apt-get remove -y azure-cli || true
          pip install azure-cli==2.76.0

shahbhavik01 avatar Sep 09 '25 17:09 shahbhavik01

For Azure DevOps you can use:

  # Can be removed once this issue is fixed: https://github.com/Azure/azure-cli/issues/32039
  - script: >-
      pip install azure-cli==2.76.0
    displayName: Pin Azure CLI to 2.76.0

mdenhoedt avatar Sep 09 '25 17:09 mdenhoedt

@yonzhan why was this issue re-categorized as a question rather than a bug?

pfrydids avatar Sep 10 '25 08:09 pfrydids

So many bugs in 2.77

Someone did lot of vibe coding it seems 😂

manasmagdum avatar Sep 10 '25 09:09 manasmagdum

I am getting the same error. solved with

      - name: Downgrade Azure CLI
        run: pip install "azure-cli==2.76.0"

When can we use the latest version. Is anyone aware of when the bug will be solved?

anulalk-dlt avatar Sep 10 '25 11:09 anulalk-dlt

If you are using the azure/cli@v2 github action, I have found success by specifying the specific azure cli version using the azcliversion argument, as mentioned in their Readme.

Example

    - name: Download batch from blob storage
      uses: azure/cli@v2
      with:
        # pin version due to https://github.com/Azure/azure-cli/issues/32039
        azcliversion: 2.76.0
        inlineScript: >
          az storage blob download-batch
          <redacted>

rmelick-muon avatar Sep 10 '25 14:09 rmelick-muon

If it helps anyone - we rolled back on Azure Devops Windows based build agents using this

- powershell: |
      Start-Process msiexec -ArgumentList ' /x {37CCEB8D-306A-4DB4-B25B-7608A093D184} /qn' -NoNewWindow -Wait
    displayName: "Uninstall Azure CLI"

  - powershell: |
      Invoke-WebRequest -Uri "https://azurecliprod.blob.core.windows.net/msi/azure-cli-2.76.0-x64.msi" -OutFile "azure-cli-2.76.0.msi"
      Start-Process msiexec -ArgumentList '/i "azure-cli-2.76.0.msi" /quiet /norestart' -NoNewWindow -Wait
    displayName: "Install Azure CLI 2.76.0"

  - script: |
      az version
    displayName: "Check Azure CLI version"

paulcmason avatar Sep 10 '25 17:09 paulcmason

Also getting same issue on az storage blob copy start-batch

rtalento avatar Sep 12 '25 06:09 rtalento

Any progress on this?

We use the Azure CLI in our build pipeline and currently seeing the same problem with 2.77

AndreRicardo-Zoetis avatar Sep 18 '25 14:09 AndreRicardo-Zoetis