Skip to content

[Backup] Supplying non-existent name or natively formatted name for container causes stack trace #4502

@tjprescott

Description

@tjprescott

Trying to run:
az backup protection backup-now -g tjp-ig -v vault1 --retain-until 01-01-2020 -c container1 -i item1

Yields:

'list' object has no attribute 'name'
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 212, in execute
    result = expanded_arg.func(params)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 377, in __call__
    return self.handler(*args, **kwargs)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 626, in _execute_command
    reraise(*sys.exc_info())
  File "/opt/az/lib/python3.6/site-packages/six.py", line 693, in reraise
    raise value
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 603, in _execute_command
    result = op(client, **kwargs) if client else op(**kwargs)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/backup/custom.py", line 198, in backup_now
    container_type, item_type)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/backup/custom.py", line 145, in show_item
    items = list_items(client, resource_group_name, vault_name, container_name, container_type, item_type)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/backup/custom.py", line 159, in list_items
    return [item for item in paged_items if item.properties.container_name.lower() in container.name.lower()]
  File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/backup/custom.py", line 159, in <listcomp>
    return [item for item in paged_items if item.properties.container_name.lower() in container.name.lower()]
AttributeError: 'list' object has no attribute 'name'

In this case, it was not clear to me that a container and item had been created by the enable-for-vm command, so I assumed that these names were the names that would be created. When I realized it expected an existing name, I tried the container name obtained by running the backup container list command. However this yields the same stack trace. This AttributeError should be caught and handled gracefully. Additionally, it is perfectly fine to use a shorthand notation (like the VM name in this case) but:

  1. It should be clearly documented in help
  2. The parameter should definitely accept the format of name that the container object actually uses.

Environment summary

Install Method: How did you install the CLI? (e.g. pip, interactive script, apt-get, Docker, MSI, nightly)
Answer here: WGET

CLI Version: What version of the CLI and modules are installed? (Use az --version)
Answer here: azure-cli (2.0.17+dev)

acr (2.0.11+dev)
acs (2.0.15+dev)
appservice (0.1.16+dev)
backup (1.0.0+dev)
batch (3.1.3+dev)
billing (0.1.4+dev)
cdn (0.0.8+dev)
cloud (2.0.7+dev)
cognitiveservices (0.1.7+dev)
command-modules-nspkg (2.0.1+dev)
component (2.0.7+dev)
configure (2.0.10+dev)
consumption (0.1.4+dev)
container (0.1.10+dev)
core (2.0.16+dev)
cosmosdb (0.1.12+dev)
dla (0.0.11+dev)
dls (0.0.13+dev)
eventgrid (0.1.3+dev)
extension (0.0.2+dev)
feedback (2.0.6+dev)
find (0.2.6+dev)
interactive (0.3.9+dev)
iot (0.1.11+dev)
keyvault (2.0.10+dev)
lab (0.0.10+dev)
monitor (0.0.9+dev)
network (2.0.14+dev)
nspkg (3.0.1+dev)
profile (2.0.12+dev)
rdbms (0.0.6+dev)
redis (0.2.8+dev)
resource (2.0.14+dev)
role (2.0.11+dev)
servicefabric (0.0.3+dev)
sql (2.0.11+dev)
storage (2.0.15+dev)
vm (2.0.14+dev)

OS Version: What OS and version are you using?
Answer here: WSL

Shell Type: What shell are you using? (e.g. bash, cmd.exe, Bash on Windows)
Answer here: Bash on Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    Recovery Services Backupaz backupRecoveryServicesService AttentionThis issue is responsible by Azure service team.bugThis issue requires a change to an existing behavior in the product in order to be resolved.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions