gurudesh/pytracebugs huggingface dataset:
# Buggy code
def acr_credential_show(cmd, client, registry_name, resource_group_name=None):
    return get_acr_credentials(cmd.cli_ctx, client, registry_name, resource_group_name)


# Traceback (AttributeError)
C:\Users\marsma>az acr login --name acr604
'bool' object has no attribute 'rstrip'
Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\knack\cli.py", line 193, in invoke
cmd_result = self.invocation.execute(args)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\core\commands\__init__.py", line 319, in execute
six.reraise(*sys.exc_info())
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\six.py", line 693, in reraise
raise value
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\core\commands\__init__.py", line 292, in execute
result = cmd(params)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\core\commands\__init__.py", line 169, in __call__
return super(AzCliCommand, self).__call__(*args, **kwargs)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\knack\commands.py", line 109, in __call__
return self.handler(*args, **kwargs)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\core\__init__.py", line 328, in default_command_handler
result = op(**command_args)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\command_modules\acr\custom.py", line 195, in acr_login
password=password)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\command_modules\acr\_docker_utils.py", line 194, in get_login_credentials
only_refresh_token=True)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\command_modules\acr\_docker_utils.py", line 150, in _get_credentials
password = _get_aad_token(login_server, only_refresh_token, repository, permission)
File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\azure\cli\command_modules\acr\_docker_utils.py", line 35, in _get_aad_token
login_server = login_server.rstrip('/')
AttributeError: 'bool' object has no attribute 'rstrip'

# Fixed code
def acr_credential_show(cmd, client, registry_name, resource_group_name=None):
    registry, resource_group_name = get_registry_by_name(
        cmd.cli_ctx, registry_name, resource_group_name
    )

    if registry.admin_user_enabled:  # pylint: disable=no-member
        return client.list_credentials(resource_group_name, registry_name)

    admin_not_enabled_error(registry_name)
# Buggy code
def get_location_completion_list(cli_ctx, prefix, **kwargs):  # pylint: disable=unused-argument
    result = get_subscription_locations(cli_ctx)
    return [l.name for l in result]


# Traceback (IOError)
$ az
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/dist-packages/azure/cli/__main__.py", line 35, in <module>
help_cls=AzCliHelp)
File "/usr/local/lib/python2.7/dist-packages/azure/cli/core/__init__.py", line 47, in __init__
ACCOUNT.load(os.path.join(azure_folder, 'azureProfile.json'))
File "/usr/local/lib/python2.7/dist-packages/azure/cli/core/_session.py", line 42, in load
self.save()
File "/usr/local/lib/python2.7/dist-packages/azure/cli/core/_session.py", line 46, in save
with codecs_open(self.filename, 'w', encoding=self._encoding) as f:
File "/usr/lib/python2.7/codecs.py", line 896, in open
file = __builtin__.open(filename, mode, buffering)
IOError: [Errno 2] No such file or directory: '/root/.azure/azureProfile.json'
$

# Fixed code
def get_location_completion_list(cmd, prefix, namespace, **kwargs):  # pylint: disable=unused-argument
    result = get_subscription_locations(cmd.cli_ctx)
    return [l.name for l in result]
# Buggy code
def get_resource_group_completion_list(cli_ctx, prefix, **kwargs):  # pylint: disable=unused-argument
    result = get_resource_groups(cli_ctx)
    return [l.name for l in result]


# Traceback (IOError)
$ az
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/dist-packages/azure/cli/__main__.py", line 35, in <module>
help_cls=AzCliHelp)
File "/usr/local/lib/python2.7/dist-packages/azure/cli/core/__init__.py", line 47, in __init__
ACCOUNT.load(os.path.join(azure_folder, 'azureProfile.json'))
File "/usr/local/lib/python2.7/dist-packages/azure/cli/core/_session.py", line 42, in load
self.save()
File "/usr/local/lib/python2.7/dist-packages/azure/cli/core/_session.py", line 46, in save
with codecs_open(self.filename, 'w', encoding=self._encoding) as f:
File "/usr/lib/python2.7/codecs.py", line 896, in open
file = __builtin__.open(filename, mode, buffering)
IOError: [Errno 2] No such file or directory: '/root/.azure/azureProfile.json'
$

# Fixed code
def get_resource_group_completion_list(cmd, prefix, namespace, **kwargs):  # pylint: disable=unused-argument
    result = get_resource_groups(cmd.cli_ctx)
    return [l.name for l in result]
# Buggy code
def get_generic_completion_list(generic_list):
    def completer(prefix, action, parsed_args, **kwargs):  # pylint: disable=unused-argument
        return generic_list

    return completer


# Traceback (IOError)
$ az
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/dist-packages/azure/cli/__main__.py", line 35, in <module>
help_cls=AzCliHelp)
File "/usr/local/lib/python2.7/dist-packages/azure/cli/core/__init__.py", line 47, in __init__
ACCOUNT.load(os.path.join(azure_folder, 'azureProfile.json'))
File "/usr/local/lib/python2.7/dist-packages/azure/cli/core/_session.py", line 42, in load
self.save()
File "/usr/local/lib/python2.7/dist-packages/azure/cli/core/_session.py", line 46, in save
with codecs_open(self.filename, 'w', encoding=self._encoding) as f:
File "/usr/lib/python2.7/codecs.py", line 896, in open
file = __builtin__.open(filename, mode, buffering)
IOError: [Errno 2] No such file or directory: '/root/.azure/azureProfile.json'
$

# Fixed code
def get_generic_completion_list(generic_list):
    @Completer
    def completer(cmd, prefix, namespace, **kwargs):  # pylint: disable=unused-argument
        return generic_list

    return completer
# Buggy code
def completer(prefix, action, parsed_args, **kwargs):  # pylint: disable=unused-argument
    return generic_list


# Traceback (IOError)
$ az
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/lib/python2.7/dist-packages/azure/cli/__main__.py", line 35, in <module>
help_cls=AzCliHelp)
File "/usr/local/lib/python2.7/dist-packages/azure/cli/core/__init__.py", line 47, in __init__
ACCOUNT.load(os.path.join(azure_folder, 'azureProfile.json'))
File "/usr/local/lib/python2.7/dist-packages/azure/cli/core/_session.py", line 42, in load
self.save()
File "/usr/local/lib/python2.7/dist-packages/azure/cli/core/_session.py", line 46, in save
with codecs_open(self.filename, 'w', encoding=self._encoding) as f:
File "/usr/lib/python2.7/codecs.py", line 896, in open
file = __builtin__.open(filename, mode, buffering)
IOError: [Errno 2] No such file or directory: '/root/.azure/azureProfile.json'
$

# Fixed code
def completer(cmd, prefix, namespace, **kwargs):  # pylint: disable=unused-argument
    return generic_list
# Buggy code
def get_resource_group_name_by_registry_name(registry_name, resource_group_name=None):
    """Returns the resource group name for the container registry.
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    if not resource_group_name:
        arm_resource = _arm_get_resource_by_name(registry_name, ACR_RESOURCE_TYPE)
        resource_group_name = get_resource_group_name_by_resource_id(arm_resource.id)
    return resource_group_name


# 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 get_resource_group_name_by_registry_name(registry_name, resource_group_name=None):
    """Returns the resource group name for the container registry.
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    if not resource_group_name:
        arm_resource = _arm_get_resource_by_name(registry_name, REGISTRY_RESOURCE_TYPE)
        resource_group_name = get_resource_group_name_by_resource_id(arm_resource.id)
    return resource_group_name
# Buggy code
def validate_sku_update(sku_parameter):
    """Validates a registry SKU update parameter.
    :param object sku_parameter: The registry SKU update parameter
    """
    if sku_parameter is None:
        return

    if isinstance(sku_parameter, dict):
        if (
            "name" not in sku_parameter
            or sku_parameter["name"] not in MANAGED_REGISTRY_SKU
        ):
            _invalid_sku_update()
    elif isinstance(sku_parameter, Sku):
        if sku_parameter.name not in MANAGED_REGISTRY_SKU:
            _invalid_sku_update()
    else:
        _invalid_sku_update()


# 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 validate_sku_update(current_sku, sku_parameter):
    """Validates a registry SKU update parameter.
    :param object sku_parameter: The registry SKU update parameter
    """
    if sku_parameter is None:
        return

    if isinstance(sku_parameter, dict):
        if "name" not in sku_parameter:
            _invalid_sku_update()
        if (
            sku_parameter["name"] not in CLASSIC_REGISTRY_SKU
            and sku_parameter["name"] not in MANAGED_REGISTRY_SKU
        ):
            _invalid_sku_update()
        if (
            current_sku in MANAGED_REGISTRY_SKU
            and sku_parameter["name"] in CLASSIC_REGISTRY_SKU
        ):
            _invalid_sku_downgrade()
    elif isinstance(sku_parameter, Sku):
        if (
            current_sku in MANAGED_REGISTRY_SKU
            and sku_parameter.name in CLASSIC_REGISTRY_SKU
        ):
            _invalid_sku_downgrade()
    else:
        _invalid_sku_update()
# Buggy code
def _invalid_sku_update():
    raise CLIError(
        "Please specify SKU by '--sku SKU' or '--set sku.name=SKU'. Allowed SKU: {}.".format(
            MANAGED_REGISTRY_SKU
        )
    )


# 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 _invalid_sku_update():
    raise CLIError(
        "Please specify SKU by '--sku SKU' or '--set sku.name=SKU'. Allowed SKUs: {0}".format(
            MANAGED_REGISTRY_SKU
        )
    )
# Buggy code
def acr_update_custom(
    instance, sku=None, storage_account_name=None, admin_enabled=None, tags=None
):
    if sku is not None:
        instance.sku = Sku(name=sku)

    if storage_account_name is not None:
        instance.storage_account = StorageAccountParameters(storage_account_name, "")

    if admin_enabled is not None:
        instance.admin_user_enabled = admin_enabled == "true"

    if tags is not None:
        instance.tags = tags

    return instance


# 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_update_custom(
    instance, sku=None, storage_account_name=None, admin_enabled=None, tags=None
):
    if sku is not None:
        instance.sku = Sku(name=sku)

    if storage_account_name is not None:
        instance.storage_account = StorageAccountProperties(
            get_resource_id_by_storage_account_name(storage_account_name)
        )

    if admin_enabled is not None:
        instance.admin_user_enabled = admin_enabled == "true"

    if tags is not None:
        instance.tags = tags

    return instance
# Buggy code
def acr_update_get(
    client,  # pylint: disable=unused-argument
    registry_name,
    resource_group_name=None,
):
    """Returns an empty RegistryUpdateParameters object.
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    try:
        managed_registry_validation(registry_name, resource_group_name)
        return ManagedRegistryUpdateParameters()
    except:  # pylint: disable=bare-except
        return BasicRegistryUpdateParameters()


# 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_update_get(client):  # pylint: disable=unused-argument
    """Returns an empty RegistryUpdateParameters object."""
    return RegistryUpdateParameters()
# Buggy code
def acr_show_usage(registry_name, resource_group_name=None):
    """Gets the quota usages for the specified container registry.
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    _, resource_group_name = managed_registry_validation(
        registry_name,
        resource_group_name,
        "Usage is not supported for registries in Basic SKU.",
    )
    client = get_acr_service_client(MANAGED_REGISTRY_API_VERSION).registries

    return client.list_usages(resource_group_name, registry_name)


# 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_show_usage(registry_name, resource_group_name=None):
    """Gets the quota usages for the specified container registry.
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    _, resource_group_name = validate_managed_registry(
        registry_name,
        resource_group_name,
        "Usage is only supported for managed registries.",
    )
    client = get_acr_service_client().registries

    return client.list_usages(resource_group_name, registry_name)
# Buggy code
def acr_webhook_list(registry_name, resource_group_name=None):
    """Lists all the webhooks for the specified container registry."
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    _, resource_group_name = managed_registry_validation(
        registry_name, resource_group_name, WEBHOOKS_NOT_SUPPORTED
    )
    client = get_acr_service_client(WEBHOOK_API_VERSION).webhooks

    return client.list(resource_group_name, registry_name)


# 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_webhook_list(registry_name, resource_group_name=None):
    """Lists all the webhooks for the specified container registry."
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    _, resource_group_name = validate_managed_registry(
        registry_name, resource_group_name, WEBHOOKS_NOT_SUPPORTED
    )
    client = get_acr_service_client().webhooks

    return client.list(resource_group_name, registry_name)
# Buggy code
def acr_webhook_delete(webhook_name, registry_name, resource_group_name=None):
    """Deletes a webhook from a container registry.
    :param str webhook_name: The name of webhook
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    _, resource_group_name = managed_registry_validation(
        registry_name, resource_group_name, WEBHOOKS_NOT_SUPPORTED
    )
    client = get_acr_service_client(WEBHOOK_API_VERSION).webhooks

    return client.delete(resource_group_name, registry_name, webhook_name)


# 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_webhook_delete(webhook_name, registry_name, resource_group_name=None):
    """Deletes a webhook from a container registry.
    :param str webhook_name: The name of webhook
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    _, resource_group_name = validate_managed_registry(
        registry_name, resource_group_name, WEBHOOKS_NOT_SUPPORTED
    )
    client = get_acr_service_client().webhooks

    return client.delete(resource_group_name, registry_name, webhook_name)
# Buggy code
def acr_webhook_show(webhook_name, registry_name, resource_group_name=None):
    """Gets the properties of the specified webhook.
    :param str webhook_name: The name of webhook
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    _, resource_group_name = managed_registry_validation(
        registry_name, resource_group_name, WEBHOOKS_NOT_SUPPORTED
    )
    client = get_acr_service_client(WEBHOOK_API_VERSION).webhooks

    return client.get(resource_group_name, registry_name, webhook_name)


# 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_webhook_show(webhook_name, registry_name, resource_group_name=None):
    """Gets the properties of the specified webhook.
    :param str webhook_name: The name of webhook
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    _, resource_group_name = validate_managed_registry(
        registry_name, resource_group_name, WEBHOOKS_NOT_SUPPORTED
    )
    client = get_acr_service_client().webhooks

    return client.get(resource_group_name, registry_name, webhook_name)
# Buggy code
def acr_webhook_get_config(webhook_name, registry_name, resource_group_name=None):
    """Gets the configuration of service URI and custom headers for the webhook.
    :param str webhook_name: The name of webhook
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    _, resource_group_name = managed_registry_validation(
        registry_name, resource_group_name, WEBHOOKS_NOT_SUPPORTED
    )
    client = get_acr_service_client(WEBHOOK_API_VERSION).webhooks

    return client.get_callback_config(resource_group_name, registry_name, webhook_name)


# 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_webhook_get_config(webhook_name, registry_name, resource_group_name=None):
    """Gets the configuration of service URI and custom headers for the webhook.
    :param str webhook_name: The name of webhook
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    _, resource_group_name = validate_managed_registry(
        registry_name, resource_group_name, WEBHOOKS_NOT_SUPPORTED
    )
    client = get_acr_service_client().webhooks

    return client.get_callback_config(resource_group_name, registry_name, webhook_name)
# Buggy code
def acr_webhook_list_events(webhook_name, registry_name, resource_group_name=None):
    """Lists recent events for the specified webhook.
    :param str webhook_name: The name of webhook
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    _, resource_group_name = managed_registry_validation(
        registry_name, resource_group_name, WEBHOOKS_NOT_SUPPORTED
    )
    client = get_acr_service_client(WEBHOOK_API_VERSION).webhooks

    return client.list_events(resource_group_name, registry_name, webhook_name)


# 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_webhook_list_events(webhook_name, registry_name, resource_group_name=None):
    """Lists recent events for the specified webhook.
    :param str webhook_name: The name of webhook
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    _, resource_group_name = validate_managed_registry(
        registry_name, resource_group_name, WEBHOOKS_NOT_SUPPORTED
    )
    client = get_acr_service_client().webhooks

    return client.list_events(resource_group_name, registry_name, webhook_name)
# Buggy code
def acr_webhook_ping(webhook_name, registry_name, resource_group_name=None):
    """Triggers a ping event to be sent to the webhook.
    :param str webhook_name: The name of webhook
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    _, resource_group_name = managed_registry_validation(
        registry_name, resource_group_name, WEBHOOKS_NOT_SUPPORTED
    )
    client = get_acr_service_client(WEBHOOK_API_VERSION).webhooks

    return client.ping(resource_group_name, registry_name, webhook_name)


# 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_webhook_ping(webhook_name, registry_name, resource_group_name=None):
    """Triggers a ping event to be sent to the webhook.
    :param str webhook_name: The name of webhook
    :param str registry_name: The name of container registry
    :param str resource_group_name: The name of resource group
    """
    _, resource_group_name = validate_managed_registry(
        registry_name, resource_group_name, WEBHOOKS_NOT_SUPPORTED
    )
    client = get_acr_service_client().webhooks

    return client.ping(resource_group_name, registry_name, webhook_name)
# Buggy code
def _get_extension_instance_name(
    instance_view, publisher, extension_type_name, suggested_name=None
):
    extension_instance_name = suggested_name or extension_type_name
    full_type_name = ".".join([publisher, extension_type_name])
    if instance_view.extensions:
        ext = next(
            (
                x
                for x in instance_view.extensions
                if x.type.lower() == full_type_name.lower()
            ),
            None,
        )
        if ext:
            extension_instance_name = ext.name
    return extension_instance_name


# Traceback (AttributeError)
'NoneType' object has no attribute 'lower'
Traceback (most recent call last):
File "/opt/az/lib/python3.6/site-packages/azure/cli/main.py", line 36, in main
cmd_result = APPLICATION.execute(args)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/application.py", line 211, in execute
result = expanded_arg.func(params)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 346, in __call__
return self.handler(*args, **kwargs)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 545, in _execute_command
reraise(*sys.exc_info())
File "/opt/az/lib/python3.6/site-packages/six.py", line 686, in reraise
raise value
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 522, in _execute_command
result = op(client, **kwargs) if client else op(**kwargs)
File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/vm/custom.py", line 606, in set_user
return _set_linux_user(vm, resource_group_name, username, password, ssh_key_value, no_wait)
File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/vm/custom.py", line 663, in _set_linux_user
protected_settings)
File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/vm/custom.py", line 714, in _update_linux_access_extension
_ACCESS_EXT_HANDLER_NAME)
File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/vm/custom.py", line 738, in _get_extension_instance_name
if x.type.lower() == full_type_name.lower()), None)
File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/vm/custom.py", line 738, in <genexpr>
if x.type.lower() == full_type_name.lower()), None)
AttributeError: 'NoneType' object has no attribute 'lower'

# Fixed code
def _get_extension_instance_name(
    instance_view, publisher, extension_type_name, suggested_name=None
):
    extension_instance_name = suggested_name or extension_type_name
    full_type_name = ".".join([publisher, extension_type_name])
    if instance_view.extensions:
        ext = next(
            (
                x
                for x in instance_view.extensions
                if x.type and (x.type.lower() == full_type_name.lower())
            ),
            None,
        )
        if ext:
            extension_instance_name = ext.name
    return extension_instance_name
# Buggy code
def __call__(self, parser, namespace, values, option_string=None):
    """The SplitAction will take the given ID parameter and spread the parsed
    parts of the id into the individual backing fields.

    Since the id value is expected to be of type `IterateValue`, all the backing
    (dest) fields will also be of type `IterateValue`
    """
    try:
        for value in [values] if isinstance(values, str) else values:
            parts = parse_resource_id(value)
            for arg in [arg for arg in arguments.values() if arg.id_part]:
                existing_values = getattr(namespace, arg.name, None)
                if existing_values is None:
                    existing_values = IterateValue()
                existing_values.append(parts[arg.id_part])
                setattr(namespace, arg.name, existing_values)
    except Exception as ex:
        raise ValueError(ex)


# Traceback (AttributeError)
'str' object has no attribute 'append'
Traceback (most recent call last):
File "c:\users\trpresco\documents\github\azure-cli\src\azure\cli\commands\arm.py", line 110, in __call__
existing_values.append(parts[arg.id_part])
AttributeError: 'str' object has no attribute 'append'

# Fixed code
def __call__(self, parser, namespace, values, option_string=None):
    """The SplitAction will take the given ID parameter and spread the parsed
    parts of the id into the individual backing fields.

    Since the id value is expected to be of type `IterateValue`, all the backing
    (dest) fields will also be of type `IterateValue`
    """
    try:
        for value in [values] if isinstance(values, str) else values:
            parts = parse_resource_id(value)
            for arg in [arg for arg in arguments.values() if arg.id_part]:
                existing_values = getattr(namespace, arg.name, None)
                if existing_values is None:
                    existing_values = IterateValue()
                    existing_values.append(parts[arg.id_part])
                elif isinstance(existing_values, str):
                    logger.warning(
                        "Property '%s=%s' being overriden by value '%s' from IDs parameter.",  # pylint: disable=line-too-long
                        arg.name,
                        existing_values,
                        parts[arg.id_part],
                    )
                    existing_values = IterateValue()
                    existing_values.append(parts[arg.id_part])
                setattr(namespace, arg.name, existing_values)
    except Exception as ex:
        raise ValueError(ex)
# Buggy code
def format_json(obj):
    result = obj.result
    input_dict = result.__dict__ if hasattr(result, "__dict__") else result
    return (
        json.dumps(
            input_dict,
            indent=2,
            sort_keys=True,
            cls=ComplexEncoder,
            separators=(",", ": "),
        )
        + "\n"
    )


# Traceback (ValueError)
Circular reference detected
Traceback (most recent call last):
File "/opt/az/local/lib/python2.7/site-packages/azure/cli/main.py", line 39, in main
OutputProducer(formatter=formatter, file=file).out(cmd_result)
File "/opt/az/local/lib/python2.7/site-packages/azure/cli/core/_output.py", line 107, in out
output = self.formatter(obj)
File "/opt/az/local/lib/python2.7/site-packages/azure/cli/core/_output.py", line 39, in format_json
separators=(',', ': ')) + '\n'
File "/usr/lib/python2.7/json/__init__.py", line 250, in dumps
sort_keys=sort_keys, **kw).encode(obj)
File "/usr/lib/python2.7/json/encoder.py", line 209, in encode
chunks = list(chunks)
File "/usr/lib/python2.7/json/encoder.py", line 434, in _iterencode
for chunk in _iterencode_dict(o, _current_indent_level):
File "/usr/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
for chunk in chunks:
File "/usr/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
for chunk in chunks:
File "/usr/lib/python2.7/json/encoder.py", line 332, in _iterencode_list
for chunk in chunks:
File "/usr/lib/python2.7/json/encoder.py", line 332, in _iterencode_list
for chunk in chunks:
File "/usr/lib/python2.7/json/encoder.py", line 332, in _iterencode_list
for chunk in chunks:
File "/usr/lib/python2.7/json/encoder.py", line 295, in _iterencode_list
raise ValueError("Circular reference detected")
ValueError: Circular reference detected

# Fixed code
def format_json(obj):
    result = obj.result
    # OrderedDict.__dict__ is always '{}', to persist the data, convert to dict first.
    input_dict = dict(result) if hasattr(result, "__dict__") else result
    return (
        json.dumps(
            input_dict,
            indent=2,
            sort_keys=True,
            cls=ComplexEncoder,
            separators=(",", ": "),
        )
        + "\n"
    )
# Buggy code
def _add_resource_group(obj):
    if isinstance(obj, list):
        for array_item in obj:
            _add_resource_group(array_item)
    elif isinstance(obj, dict):
        try:
            if "resourceGroup" not in obj:
                if obj["id"]:
                    obj["resourceGroup"] = _parse_id(obj["id"])["resource-group"]
        except (KeyError, IndexError):
            pass
        for item_key in obj:
            _add_resource_group(obj[item_key])


# Traceback (TypeError)
$ az resource group deployment list -g derek1
expected string or buffer
Traceback (most recent call last):
File "/Users/debekoe/Repos/derekbekoe-azure-cli/src/azure-cli/azure/cli/main.py", line 34, in main
cmd_result = APPLICATION.execute(args)
File "/Users/debekoe/Repos/derekbekoe-azure-cli/src/azure-cli-core/azure/cli/core/application.py", line 126, in execute
self.raise_event(self.TRANSFORM_RESULT, event_data=event_data)
File "/Users/debekoe/Repos/derekbekoe-azure-cli/src/azure-cli-core/azure/cli/core/application.py", line 138, in raise_event
func(**kwargs)
File "/Users/debekoe/Repos/derekbekoe-azure-cli/src/azure-cli-core/azure/cli/core/extensions/transform.py", line 36, in _resource_group_transform
_add_resource_group(kwargs['event_data']['result'])
File "/Users/debekoe/Repos/derekbekoe-azure-cli/src/azure-cli-core/azure/cli/core/extensions/transform.py", line 24, in _add_resource_group
_add_resource_group(array_item)
File "/Users/debekoe/Repos/derekbekoe-azure-cli/src/azure-cli-core/azure/cli/core/extensions/transform.py", line 33, in _add_resource_group
_add_resource_group(obj[item_key])
File "/Users/debekoe/Repos/derekbekoe-azure-cli/src/azure-cli-core/azure/cli/core/extensions/transform.py", line 33, in _add_resource_group
_add_resource_group(obj[item_key])
File "/Users/debekoe/Repos/derekbekoe-azure-cli/src/azure-cli-core/azure/cli/core/extensions/transform.py", line 29, in _add_resource_group
obj['resourceGroup'] = _parse_id(obj['id'])['resource-group']
File "/Users/debekoe/Repos/derekbekoe-azure-cli/src/azure-cli-core/azure/cli/core/extensions/transform.py", line 13, in _parse_id
parts = re.split('/', strid)
File "/Users/debekoe/Repos/derekbekoe-azure-cli/env27/lib/python2.7/re.py", line 171, in split
return _compile(pattern, flags).split(string, maxsplit)
TypeError: expected string or buffer

# Fixed code
def _add_resource_group(obj):
    if isinstance(obj, list):
        for array_item in obj:
            _add_resource_group(array_item)
    elif isinstance(obj, dict):
        try:
            if "resourceGroup" not in obj:
                if obj["id"]:
                    obj["resourceGroup"] = _parse_id(obj["id"])["resource-group"]
        except (KeyError, IndexError, TypeError):
            pass
        for item_key in obj:
            _add_resource_group(obj[item_key])