Azure / Azure/azure-cli

az login crashes with "'NoneType' object is not subscriptable" in SubscriptionSelector when account has zero subscriptions (login_experience_v2)

Open
#33,555 1 comment 0 reactions 1 assignee Claimed by @isra-fel View on GitHub
Account act-codegen-extensibility-squad act-identity-squad Auto-Assign Azure CLI Team Configure customer-reported question
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

### Describe the bug

az login crashes with TypeError: 'NoneType' object is not subscriptable when the authenticated account resolves to zero subscriptions. With the new login experience (core.login_experience_v2, default on), SubscriptionSelector._active_one is None, and SubscriptionSelector.__call__ dereferences it while trying to print the active subscription. Authentication itself succeeds — only the subscription-selector UI crashes, so the command exits with an unhandled error instead of gracefully reporting that no subscriptions were found.

### Related command

az login --allow-no-subscriptions

### Errors

The command failed with an unexpected error. Here is the traceback:
'NoneType' object is not subscriptable
Traceback (most recent call last):
File ".../knack/cli.py", line 233, in invoke
cmd_result = self.invocation.execute(args)
File ".../azure/cli/core/commands/__init__.py", line 677, in execute
raise ex
File ".../azure/cli/core/commands/__init__.py", line 820, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
File ".../azure/cli/core/commands/__init__.py", line 789, in _run_job
result = cmd_copy(params)
File ".../azure/cli/core/commands/__init__.py", line 335, in __call__
return self.handler(*args, **kwargs)
File ".../azure/cli/core/commands/command_operation.py", line 120, in handler
return op(**command_args)
File ".../azure/cli/command_modules/profile/custom.py", line 238, in login
_select_and_set_active(profile, subscriptions)
File ".../azure/cli/command_modules/profile/custom.py", line 128, in _select_and_set_active
selected = SubscriptionSelector(subscriptions)()
File ".../azure/cli/command_modules/profile/_subscription_selector.py", line 72, in __call__
f"'{self._active_one[_SUBSCRIPTION_NAME]}' ({self._active_one[_SUBSCRIPTION_ID]}).\n")
TypeError: 'NoneType' object is not subscriptable

### Issue script & Debug output

# Reproduction script
az config set core.login_experience_v2=on # default; shown for clarity
az login --allow-no-subscriptions --debug
I'll attach the redacted --debug log. The relevant part is the crash at the
"Retrieving tenants and subscriptions for the selection..." stage, in
_subscription_selector.py:72, after a successful token acquisition that
returns an empty subscription set. Disabling the v2 experience
(az config set core.login_experience_v2=off) avoids the crash and instead
prints [], confirming the underlying state is simply "no subscriptions".

(Run the command above, then paste the debug output here — remember to scrub tenant IDs, object IDs, UPNs, and tokens before posting.)

### Expected behavior

When the account has no accessible subscriptions, az login should complete and report that no subscriptions were found — the same graceful result produced with core.login_experience_v2=off (which returns []) — rather than raising an unhandled TypeError. SubscriptionSelector should guard against self._active_one is None (empty subscription list).

### Environment Summary

azure-cli 2.87.0
core 2.87.0
telemetry 1.1.0

Extensions:
account 0.2.5

Dependencies:
msal 1.36.0
azure-mgmt-resource 24.0.0

Python (Linux) 3.12.3 (main, Mar 23 2026, 19:04:32) [GCC 13.3.0]
Installation: pipx

### Additional context

The zero-subscription state was triggered by an account that authenticates successfully but has no subscription/tenant membership. Regardless of why the account has no subscriptions, the CLI should not crash on the empty set — this is a missing null-guard in the v2 subscription selector. Workaround for affected users: az config set core.login_experience_v2=off.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.