Skip to content

Commit 40c6098

Browse files
authored
{Profile} Hotfix: az login: fix KeyError: 'displayName' (#12824)
1 parent 8abee4b commit 40c6098

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/azure-cli-core/azure/cli/core/_profile.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -877,10 +877,12 @@ def _find_using_common_tenant(self, access_token, resource):
877877
tenants = client.tenants.list()
878878
for t in tenants:
879879
tenant_id = t.tenant_id
880-
if not hasattr(t, 'display_name'): # Available since 2018-06-01
881-
t.display_name = ""
882-
if hasattr(t, 'additional_properties'): # remove this line once SDK is fixed
883-
t.display_name = t.additional_properties['displayName']
880+
# display_name is available since /tenants?api-version=2018-06-01,
881+
# not available in /tenants?api-version=2016-06-01
882+
if not hasattr(t, 'display_name'):
883+
t.display_name = None
884+
if hasattr(t, 'additional_properties'): # Remove this line once SDK is fixed
885+
t.display_name = t.additional_properties.get('displayName')
884886
temp_context = self._create_auth_context(tenant_id)
885887
try:
886888
temp_credentials = temp_context.acquire_token(resource, self.user_id, _CLIENT_ID)
@@ -922,14 +924,20 @@ def _find_using_common_tenant(self, access_token, resource):
922924
logger.warning("The following tenants don't contain accessible subscriptions. "
923925
"Use 'az login --allow-no-subscriptions' to have tenant level access.")
924926
for t in empty_tenants:
925-
logger.warning("%s '%s'", t.tenant_id, t.display_name)
927+
if t.display_name:
928+
logger.warning("%s '%s'", t.tenant_id, t.display_name)
929+
else:
930+
logger.warning("%s", t.tenant_id)
926931

927932
# Show warning for MFA tenants
928933
if mfa_tenants:
929934
logger.warning("The following tenants require Multi-Factor Authentication (MFA). "
930935
"Use 'az login --tenant TENANT_ID' to explicitly login to a tenant.")
931936
for t in mfa_tenants:
932-
logger.warning("%s '%s'", t.tenant_id, t.display_name)
937+
if t.display_name:
938+
logger.warning("%s '%s'", t.tenant_id, t.display_name)
939+
else:
940+
logger.warning("%s", t.tenant_id)
933941
return all_subscriptions
934942

935943
def _find_using_specific_tenant(self, tenant, access_token):

src/azure-cli/HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Release History
1010

1111
* Fix wrong version of azure-mgmt-containerregistry for Linux
1212

13+
**Profile**
14+
15+
* az login: Fix login failure with cloud profiles other than `latest`
16+
1317
2.3.0
1418
++++++
1519

0 commit comments

Comments
 (0)