Skip to content

v2.77 fails with ERROR: cannot use a string pattern on a bytes-like object #32103

@z93blom

Description

@z93blom

Describe the bug

When running the following script in our Azure Devops pipeline, az-cli version 2.77 fails with the following stacktrace. Reverting back to 2.76 works.

This is similar to #32091 & #32039, but with a different stacktrace, pointing to either the same root cause but in a different location, or at least a similar issue.

Related command

az storage blob delete-batch

Errors

ERROR: The command failed with an unexpected error. Here is the traceback:
ERROR: 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 357, in new_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 800, in storage_blob_delete_batch
    source_blobs = list(collect_blob_objects(client, source_container_name, 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

See errors above

Expected behavior

The command to work as it did in az-cli 2.76

Environment Summary

Azure Devops (pipelines from pipeline definitions in repo)
az-cli version 2.77

[command]/usr/bin/az --version
2025-09-11T10:17:33.7493596Z azure-cli                         2.77.0
2025-09-11T10:17:33.7548400Z 
2025-09-11T10:17:33.7549459Z core                              2.77.0
2025-09-11T10:17:33.7549901Z telemetry                          1.1.0
2025-09-11T10:17:33.7550542Z 
2025-09-11T10:17:33.7551496Z Extensions:
2025-09-11T10:17:33.7552175Z azure-devops                       1.0.2
2025-09-11T10:17:33.7552768Z 
2025-09-11T10:17:33.7553752Z Dependencies:
2025-09-11T10:17:33.7554530Z msal                            1.34.0b1
2025-09-11T10:17:33.7555219Z azure-mgmt-resource               23.3.0
2025-09-11T10:17:33.7555723Z 
2025-09-11T10:17:33.7556738Z Python location '/opt/az/bin/python3'
2025-09-11T10:17:33.7557557Z Config directory '/home/vsts/.azure'
2025-09-11T10:17:33.7558641Z Extensions directory '/opt/az/azcliextensions'
2025-09-11T10:17:33.7559074Z 
2025-09-11T10:17:33.7560160Z Python (Linux) 3.13.7 (main, Aug 26 2025, 08:47:19) [GCC 13.3.0]
2025-09-11T10:17:33.7568851Z 
2025-09-11T10:17:33.7569808Z Legal docs and information: aka.ms/AzureCliLegal
2025-09-11T10:17:33.7570225Z 
2025-09-11T10:17:33.7570946Z 
2025-09-11T10:17:33.7572185Z Your CLI is up-to-date.

Additional context

Workaround for now:
revert to az-cli v1.76 with the following script executed before running the az commands:

- script: |
                # Install the desired version using pip
                pip install azure-cli==2.76.0
                # Verify the installed version
                az --version
              displayName: 'Install Specific Azure CLI Version'

Metadata

Metadata

Labels

Auto-AssignAuto assign by botAzure CLI TeamThe command of the issue is owned by Azure CLI teamPossible-SolutionSimilar-IssueStorageaz storagecustomer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions