# Buggy code
def acr_create(
    registry_name,
    resource_group_name,
    sku,
    location=None,
    storage_account_name=None,
    admin_enabled="false",
    deployment_name=None,
):
    """Creates a container registry.
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    :param str sku: The SKU of the container registry
    :param str location: The name of location
    :param str storage_account_name: The name of storage account
    :param str admin_enabled: Indicates whether the admin user is enabled
    :param str deployment_name: The name of the deployment
    """
    client = get_acr_service_client().registries
    admin_user_enabled = admin_enabled == "true"

    if sku == SkuName.basic.value:
        if storage_account_name is None:
            storage_account_name = random_storage_account_name(registry_name)
            logger.warning(
                "A new storage account '%s' will be created in resource group '%s'.",
                storage_account_name,
                resource_group_name,
            )
            LongRunningOperation()(
                arm_deploy_template_new_storage(
                    resource_group_name,
                    registry_name,
                    location,
                    sku,
                    storage_account_name,
                    admin_user_enabled,
                    deployment_name,
                )
            )
        else:
            LongRunningOperation()(
                arm_deploy_template_existing_storage(
                    resource_group_name,
                    registry_name,
                    location,
                    sku,
                    storage_account_name,
                    admin_user_enabled,
                    deployment_name,
                )
            )
    else:
        if storage_account_name:
            logger.warning(
                "The registry '%s' in '%s' SKU is a managed registry. The specified storage account will be ignored.",
                registry_name,
                sku,
            )
        LongRunningOperation()(
            arm_deploy_template_managed_storage(
                resource_group_name,
                registry_name,
                location,
                sku,
                admin_user_enabled,
                deployment_name,
            )
        )

    registry = client.get(resource_group_name, registry_name)
    logger.warning("\nCreate a new service principal and assign access:")
    logger.warning(
        "  az ad sp create-for-rbac --scopes %s --role Owner --password <password>",
        registry.id,
    )  # pylint: disable=no-member
    logger.warning("\nUse an existing service principal and assign access:")
    logger.warning(
        "  az role assignment create --scope %s --role Owner --assignee <app-id>",
        registry.id,
    )  # pylint: disable=no-member

    return registry


# Traceback (AttributeError)
$ az acr repository delete -n myRegistry -u myUser -p myPass --repository myorg/myrepo

'NoneType' object has no attribute 'tier'
Traceback (most recent call last):
File "/usr/lib64/az/lib/python2.7/site-packages/azure/cli/main.py", line 36, in main
cmd_result = APPLICATION.execute(args)
File "/usr/lib64/az/lib/python2.7/site-packages/azure/cli/core/application.py", line 212, in execute
result = expanded_arg.func(params)
File "/usr/lib64/az/lib/python2.7/site-packages/azure/cli/core/commands/__init__.py", line 377, in __call__
return self.handler(*args, **kwargs)
File "/usr/lib64/az/lib/python2.7/site-packages/azure/cli/core/commands/__init__.py", line 626, in _execute_command
reraise(*sys.exc_info())
File "/usr/lib64/az/lib/python2.7/site-packages/azure/cli/core/commands/__init__.py", line 603, in _execute_command
result = op(client, **kwargs) if client else op(**kwargs)
File "/usr/lib64/az/lib/python2.7/site-packages/azure/cli/command_modules/acr/repository.py", line 281, in acr_repository_delete
registry_name, resource_group_name, DELETE_NOT_SUPPORTED)
File "/usr/lib64/az/lib/python2.7/site-packages/azure/cli/command_modules/acr/_utils.py", line 286, in managed_registry_validation
if arm_resource.sku.tier == SkuTier.basic.value:
AttributeError: 'NoneType' object has no attribute 'tier'

# Fixed code
def acr_create(
    registry_name,
    resource_group_name,
    sku,
    location=None,
    storage_account_name=None,
    admin_enabled="false",
    deployment_name=None,
):
    """Creates a container registry.
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    :param str sku: The SKU of the container registry
    :param str location: The name of location
    :param str storage_account_name: The name of storage account
    :param str admin_enabled: Indicates whether the admin user is enabled
    :param str deployment_name: The name of the deployment
    """
    if sku == SkuName.basic.value and storage_account_name:
        raise CLIError(
            "Please specify '--sku Basic' without providing an existing storage account "
            "to create a managed registry, or specify '--sku Classic --storage-account-name {}' "
            "to create a Classic registry using storage account `{}`.".format(
                storage_account_name, storage_account_name
            )
        )

    client = get_acr_service_client().registries
    admin_user_enabled = admin_enabled == "true"

    if sku == SkuName.classic.value:
        if storage_account_name is None:
            storage_account_name = random_storage_account_name(registry_name)
            logger.warning(
                "A new storage account '%s' will be created in resource group '%s'.",
                storage_account_name,
                resource_group_name,
            )
            LongRunningOperation()(
                arm_deploy_template_new_storage(
                    resource_group_name,
                    registry_name,
                    location,
                    sku,
                    storage_account_name,
                    admin_user_enabled,
                    deployment_name,
                )
            )
        else:
            LongRunningOperation()(
                arm_deploy_template_existing_storage(
                    resource_group_name,
                    registry_name,
                    location,
                    sku,
                    storage_account_name,
                    admin_user_enabled,
                    deployment_name,
                )
            )
    else:
        if storage_account_name:
            logger.warning(
                "The registry '%s' in '%s' SKU is a managed registry. The specified storage account will be ignored.",
                registry_name,
                sku,
            )
        LongRunningOperation()(
            arm_deploy_template_managed_storage(
                resource_group_name,
                registry_name,
                location,
                sku,
                admin_user_enabled,
                deployment_name,
            )
        )

    registry = client.get(resource_group_name, registry_name)
    logger.warning("\nCreate a new service principal and assign access:")
    logger.warning(
        "  az ad sp create-for-rbac --scopes %s --role Owner --password <password>",
        registry.id,
    )  # pylint: disable=no-member
    logger.warning("\nUse an existing service principal and assign access:")
    logger.warning(
        "  az role assignment create --scope %s --role Owner --assignee <app-id>",
        registry.id,
    )  # pylint: disable=no-member

    return registry