{Profile} Fix #31992: az login: Do not launch SubscriptionSelector when there is no accessible tenant#31997
{Profile} Fix #31992: az login: Do not launch SubscriptionSelector when there is no accessible tenant#31997
az login: Do not launch SubscriptionSelector when there is no accessible tenant#31997Conversation
️✔️AzureCLI-FullTest
|
|
Hi @jiasli, |
️✔️AzureCLI-BreakingChangeTest
|
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
| selected = SubscriptionSelector(subscriptions)() | ||
| profile.set_active_subscription(selected[_SUBSCRIPTION_ID]) | ||
| else: | ||
| print("\nNo accessible tenant. Make sure your account has access to at least one tenant.\n") |
There was a problem hiding this comment.
#3150 made az login not fail when --allow-no-subscriptions is provided and the user account has no accessible tenant.
9c50829 to
0016cc2
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where az login --allow-no-subscriptions crashes with an AttributeError when logging in with an account that has no access to any tenant. The fix adds a check to prevent launching the SubscriptionSelector when there are no subscriptions, instead displaying an appropriate error message.
Changes:
- Added conditional check to only launch
SubscriptionSelectorwhen subscriptions list is not empty - Added user-friendly error message when no accessible tenant is found
- Added code comments explaining the behavior when
--allow-no-subscriptionsis used
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # When --allow-no-subscriptions is specified, and the account | ||
| # - has access to tenant, but no subscription, `subscriptions` will be the tenant account | ||
| # - has access to no tenant, `subscriptions` will be []. This line will be hit. | ||
| print("\nNo accessible tenant. Make sure your account has access to at least one tenant.\n") |
There was a problem hiding this comment.
Consider using logger.warning or logger.error instead of print for the error message to be consistent with CLI logging patterns. Looking at the surrounding code (lines 220), logger.warning is used for warnings, and this seems like an error or warning message that should follow the same pattern.
| print("\nNo accessible tenant. Make sure your account has access to at least one tenant.\n") | |
| logger.warning("\nNo accessible tenant. Make sure your account has access to at least one tenant.\n") |
Related command
az loginDescription
Fix #31992
az login --allow-no-subscriptionsfails when there is no accessible tenant:This happens when a Microsoft account (not work or school account) is used to log in, but the account is not added to any Entra tenant.
This PR makes
az loginnot launchSubscriptionSelectorwhen there is no accessible tenant.Testing Guide
Log in with a Microsoft account that doesn't have access to any tenant.