Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions src/azure-cli-core/azure/cli/core/_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,7 @@ def _normalize_properties(self, user, subscriptions, is_service_principal, cert_
if subscription_dict[_SUBSCRIPTION_NAME] != _TENANT_LEVEL_ACCOUNT_NAME:
if hasattr(s, 'home_tenant_id'):
subscription_dict[_HOME_TENANT_ID] = s.home_tenant_id
if hasattr(s, 'managed_by_tenants'):
if s.managed_by_tenants is None:
# managedByTenants is missing from the response. This is a known service issue:
# https://github.com/Azure/azure-rest-api-specs/issues/9567
# pylint: disable=line-too-long
raise CLIError("Invalid profile is used for cloud '{cloud_name}'. "
"To configure the cloud profile, run `az cloud set --name {cloud_name} --profile <profile>(e.g. 2019-03-01-hybrid)`. "
"For more information about using Azure CLI with Azure Stack, see "
"https://docs.microsoft.com/azure-stack/user/azure-stack-version-profiles-azurecli2"
.format(cloud_name=self.cli_ctx.cloud.name))
if getattr(s, 'managed_by_tenants', None) is not None:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • If managed_by_tenants doesn't exist, getattr returns None and this if evaluates to False
  • If managed_by_tenants is [], getattr returns [] and this if evaluates to True, so [] is preserved

Copy link
Member Author

@jiasli jiasli Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 years later, I feel it was lucky that we didn't merge this PR.

There are 3 conditions:

# Condition 1: managedByTenants missing
{

}

# Condition 2: managedByTenants is null
{
    "managedByTenants": null
}

# Condition 3: managedByTenants is empty list []
{
    "managedByTenants": []
}

This statement doesn't take condition 2 "managedByTenants": null into consideration. Even though this has never been observed, if ARM returns "managedByTenants": null, Azure CLI output will omit managedByTenants.

Also, for condition 1, the absence of managedByTenants from ARM's Subscriptions - List REST API will propagate all the way to Azure CLI output, causing breaking change.

subscription_dict[_MANAGED_BY_TENANTS] = [{_TENANT_ID: t.tenant_id} for t in s.managed_by_tenants]

consolidated.append(subscription_dict)
Expand Down