Skip to content

AttributeError: module 'redis' has no attribute 'client' #34227

Open

Description

@thorfi

Describe the bug

After doing:

brew uninstall --formula azure-cli
brew install azure-cli

To migrate to the Cask version of az, the following error is appearing on any az commands:

% az login
The command failed with an unexpected error. Here is the traceback:
module 'redis' has no attribute 'client'
...
AttributeError: module 'redis' has no attribute 'client'

Related command

az login

Errors

% az login
The command failed with an unexpected error. Here is the traceback:
module 'redis' has no attribute 'client'
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/azure-cli/2.91.0/libexec/lib/python3.14/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/homebrew/Caskroom/azure-cli/2.91.0/libexec/lib/python3.14/site-packages/azure/cli/core/commands/__init__.py", line 677, in execute
    raise ex
  File "/opt/homebrew/Caskroom/azure-cli/2.91.0/libexec/lib/python3.14/site-packages/azure/cli/core/commands/__init__.py", line 820, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/azure-cli/2.91.0/libexec/lib/python3.14/site-packages/azure/cli/core/commands/__init__.py", line 789, in _run_job
    result = cmd_copy(params)
  File "/opt/homebrew/Caskroom/azure-cli/2.91.0/libexec/lib/python3.14/site-packages/azure/cli/core/commands/__init__.py", line 335, in __call__
    return self.handler(*args, **kwargs)
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/azure-cli/2.91.0/libexec/lib/python3.14/site-packages/azure/cli/core/commands/command_operation.py", line 120, in handler
    return op(**command_args)
  File "/opt/homebrew/Caskroom/azure-cli/2.91.0/libexec/lib/python3.14/site-packages/azure/cli/command_modules/profile/custom.py", line 215, in login
    subscriptions = profile.login(
        interactive,
    ...<11 lines>...
        subscription=subscription
    )
  File "/opt/homebrew/Caskroom/azure-cli/2.91.0/libexec/lib/python3.14/site-packages/azure/cli/core/_profile.py", line 164, in login
    identity = _create_identity_instance(self.cli_ctx, self._authority, tenant_id=tenant)
  File "/opt/homebrew/Caskroom/azure-cli/2.91.0/libexec/lib/python3.14/site-packages/azure/cli/core/_profile.py", line 969, in _create_identity_instance
    from .auth.identity import Identity
  File "/opt/homebrew/Caskroom/azure-cli/2.91.0/libexec/lib/python3.14/site-packages/azure/cli/core/auth/identity.py", line 18, in <module>
    from .persistence import load_persisted_token_cache, file_extensions, load_secret_store
  File "/opt/homebrew/Caskroom/azure-cli/2.91.0/libexec/lib/python3.14/site-packages/azure/cli/core/auth/persistence.py", line 12, in <module>
    from msal_extensions import (FilePersistenceWithDataProtection, KeychainPersistence, LibsecretPersistence,
                                 FilePersistence, PersistedTokenCache, CrossPlatLock)
  File "/opt/homebrew/Caskroom/azure-cli/2.91.0/libexec/lib/python3.14/site-packages/msal_extensions/__init__.py", line 11, in <module>
    from .token_cache import PersistedTokenCache, CrossPlatLock, LockError
  File "/opt/homebrew/Caskroom/azure-cli/2.91.0/libexec/lib/python3.14/site-packages/msal_extensions/token_cache.py", line 9, in <module>
    from .cache_lock import (  # pylint: disable=unused-import
    ...<2 lines>...
        )
  File "/opt/homebrew/Caskroom/azure-cli/2.91.0/libexec/lib/python3.14/site-packages/msal_extensions/cache_lock.py", line 8, in <module>
    import portalocker  # pylint: disable=import-error
    ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/azure-cli/2.91.0/libexec/lib/python3.14/site-packages/portalocker/__init__.py", line 11, in <module>
    from .redis import RedisLock
  File "/opt/homebrew/Caskroom/azure-cli/2.91.0/libexec/lib/python3.14/site-packages/portalocker/redis.py", line 21, in <module>
    class PubSubWorkerThread(redis.client.PubSubWorkerThread):
                             ^^^^^^^^^^^^
AttributeError: module 'redis' has no attribute 'client'

Issue script & Debug output

Any az command.

Expected behavior

az cli should work, not crash

Environment Summary

azure-cli 2.91.0

core 2.91.0
telemetry 1.1.0

Extensions:
account 0.2.5
application-insights 2.0.0b2
containerapp 1.3.0b5
costmanagement 1.0.0
log-analytics 1.0.0b3
log-analytics-solution 1.0.1
logic 1.1.0
portal 1.0.0b2
quota 1.0.0
redisenterprise 1.5.0b1
storagesync 1.0.1

Dependencies:
msal 1.39.0
azure-mgmt-resource 24.0.0

Python location '/opt/homebrew/opt/python@3.14/bin/python3.14'
Config directory '/Users/thorfinn/.azure'
Extensions directory '/Users/thorfinn/.azure/cliextensions'

Python (Darwin) 3.14.8 (main, Sep 30 2026, 17:55:09) [Clang 21.0.0 (clang-2100.3.34.2)]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

Additional context

No response

Activity

  1. added
    bugThis issue requires a change to an existing behavior in the product in order to be resolved.
    on Oct 15, 2026
  2. added
    customer-reportedIssues that are reported by GitHub users external to the Azure organization.
    Accountaz login/account
    Azure CLI TeamThe command of the issue is owned by Azure CLI team
    questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that
    on Oct 15, 2026
  3. yonzhan commented on Oct 15, 2026

    @yonzhan
    Collaborator

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

  4. removed
    questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that
    on Oct 15, 2026
  5. added this to the Backlog milestone on Oct 15, 2026
  6. thorfi commented on Oct 15, 2026

    @thorfi
    Author

    Yong Zhang (@yonzhan) - thanks, right now I can't use the az cli at all, so this is a big problem. I tried removing my $HOME/.azure* directories just in case, but that didn't change anything.

  7. x-engineering-agent commented on Oct 15, 2026

    @x-engineering-agent
    Contributor

    @thorfi (@thorfi), the version, migration steps and traceback already identify the failure: az login crashes while importing msal_extensions → portalocker → redis.client, before sign-in or token-cache access. This is the Python redis import, not the azure-mgmt-redis management SDK. The reported invocation also goes through bin/gitenv.sh, so we cannot yet distinguish a Cask dependency problem from that wrapper's Python import environment.

    Does az login reproduce the same redis.client error when invoked directly from a fresh terminal outside the project directory, without bin/gitenv.sh? Please share that result, removing any tokens or personal details. That single control will determine whether to investigate the Cask's installed dependencies or the wrapper's import environment; your reply will automatically resume triage.

    Posted by x-engineering-agent (Fixer)

  8. microsoft-github-policy-service commented on Oct 15, 2026

    @microsoft-github-policy-service
    Contributor

    🔔 Routing this issue to @Azure/act-identity-squad.

  9. thorfi commented on Oct 15, 2026

    @thorfi
    Author

    8. @thorfi (@thorfi), the version, migration steps and traceback already identify the failure: az login crashes while importing msal_extensions → portalocker → redis.client, before sign-in or token-cache access. This is the Python redis import, not the azure-mgmt-redis management SDK. The reported invocation also goes through bin/gitenv.sh, so we cannot yet distinguish a Cask dependency problem from that wrapper's Python import environment.
    Does az login reproduce the same redis.client error when invoked directly from a fresh terminal outside the project directory, without bin/gitenv.sh? Please share that result, removing any tokens or personal details. That single control will determine whether to investigate the Cask's installed dependencies or the wrapper's import environment; your reply will automatically resume triage.

    I removed bin/gitenv.sh and it still crashes, but it looks like it crashes if inside my project directory (which has a directory called redis that doesn't contain any python code) but if I do it in somewhere like /tmp.

    It seems like issue is that the current az cli is adding . to the sys.path somewhere which it really should not be.

  10. thorfi commented on Oct 15, 2026

    @thorfi
    Author

    Yong Zhang (@yonzhan) FYI Not sure if you want to re-engage your AI bot, but I made a simple reproduction sequence using the azure-cli docker container:

    % docker run --rm -it mcr.microsoft.com/azure-cli:latest bash
    root [ / ]# cd /tmp
    root [ /tmp ]# mkdir redis
    root [ /tmp ]# az login
    The command failed with an unexpected error. Here is the traceback:
    module 'redis' has no attribute 'client'
    Traceback (most recent call last):
      File "/usr/lib64/az/lib/python3.12/site-packages/knack/cli.py", line 233, in invoke
        cmd_result = self.invocation.execute(args)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib64/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 677, in execute
        raise ex
      File "/usr/lib64/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 820, in _run_jobs_serially
        results.append(self._run_job(expanded_arg, cmd_copy))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib64/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 789, in _run_job
        result = cmd_copy(params)
                 ^^^^^^^^^^^^^^^^
      File "/usr/lib64/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 335, in __call__
        return self.handler(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib64/az/lib/python3.12/site-packages/azure/cli/core/commands/command_operation.py", line 120, in handler
        return op(**command_args)
               ^^^^^^^^^^^^^^^^^^
      File "/usr/lib64/az/lib/python3.12/site-packages/azure/cli/command_modules/profile/custom.py", line 215, in login
        subscriptions = profile.login(
                        ^^^^^^^^^^^^^^
      File "/usr/lib64/az/lib/python3.12/site-packages/azure/cli/core/_profile.py", line 164, in login
        identity = _create_identity_instance(self.cli_ctx, self._authority, tenant_id=tenant)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/lib64/az/lib/python3.12/site-packages/azure/cli/core/_profile.py", line 969, in _create_identity_instance
        from .auth.identity import Identity
      File "/usr/lib64/az/lib/python3.12/site-packages/azure/cli/core/auth/identity.py", line 18, in <module>
        from .persistence import load_persisted_token_cache, file_extensions, load_secret_store
      File "/usr/lib64/az/lib/python3.12/site-packages/azure/cli/core/auth/persistence.py", line 12, in <module>
        from msal_extensions import (FilePersistenceWithDataProtection, KeychainPersistence, LibsecretPersistence,
      File "/usr/lib64/az/lib/python3.12/site-packages/msal_extensions/__init__.py", line 11, in <module>
        from .token_cache import PersistedTokenCache, CrossPlatLock, LockError
      File "/usr/lib64/az/lib/python3.12/site-packages/msal_extensions/token_cache.py", line 9, in <module>
        from .cache_lock import (  # pylint: disable=unused-import
      File "/usr/lib64/az/lib/python3.12/site-packages/msal_extensions/cache_lock.py", line 8, in <module>
        import portalocker  # pylint: disable=import-error
        ^^^^^^^^^^^^^^^^^^
      File "/usr/lib64/az/lib/python3.12/site-packages/portalocker/__init__.py", line 11, in <module>
        from .redis import RedisLock
      File "/usr/lib64/az/lib/python3.12/site-packages/portalocker/redis.py", line 21, in <module>
        class PubSubWorkerThread(redis.client.PubSubWorkerThread):
                                 ^^^^^^^^^^^^
    AttributeError: module 'redis' has no attribute 'client'
    To check existing issues, please visit: https://github.com/Azure/azure-cli/issues
  11. thorfi commented on Oct 15, 2026

    @thorfi
    Author

    Ping Yeming Liu (@isra-fel) ^ reproduction above.

    Also I can confirm that setting export PYTHONSAFEPATH=1 before running az does work around the problem.

  12. microsoft-github-policy-service commented on Oct 16, 2026

    @microsoft-github-policy-service
    Contributor

    🔔 Routing this issue to @Azure/act-identity-squad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Accountaz login/accountAuto-AssignAuto assign by botAzure CLI TeamThe command of the issue is owned by Azure CLI teamact-identity-squadbugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions