# Buggy code
def add_lb_backend_address_pool_address(
    cmd,
    resource_group_name,
    load_balancer_name,
    backend_address_pool_name,
    address_name,
    vnet,
    ip_address,
):
    client = network_client_factory(cmd.cli_ctx).load_balancer_backend_address_pools
    address_pool = client.get(
        resource_group_name, load_balancer_name, backend_address_pool_name
    )
    (LoadBalancerBackendAddress, VirtualNetwork) = cmd.get_models(
        "LoadBalancerBackendAddress", "VirtualNetwork"
    )
    new_address = LoadBalancerBackendAddress(
        name=address_name,
        virtual_network=VirtualNetwork(id=vnet) if vnet else None,
        ip_address=ip_address if ip_address else None,
    )
    address_pool.load_balancer_backend_addresses.append(new_address)
    return client.create_or_update(
        resource_group_name, load_balancer_name, backend_address_pool_name, address_pool
    )


# Traceback (AttributeError)
john@Azure:~$ az network lb address-pool address add --lb-name myLB2 --pool-name myLB2bepool --resource-group myResourceGroup -n "address-name" --vnet virtualNetwork1 --ip-address 10.0.1.8
Command group 'network lb address-pool address' is in preview. It may be changed/removed in a future release.
The command failed with an unexpected error. Here is the traceback:

'NoneType' object has no attribute 'append'
Traceback (most recent call last):
File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 215, in invoke
cmd_result = self.invocation.execute(args)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 654, in execute
raise ex
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 718, in _run_jobs_serially
results.append(self._run_job(expanded_arg, cmd_copy))
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 711, in _run_job
six.reraise(*sys.exc_info())
File "/opt/az/lib/python3.6/site-packages/six.py", line 703, in reraise
raise value
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 688, in _run_job
result = cmd_copy(params)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 325, in __call__
return self.handler(*args, **kwargs)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 545, in default_command_handler
return op(**command_args)
File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/network/custom.py", line 2989, in add_lb_backend_address_pool_address
address_pool.load_balancer_backend_addresses.append(new_address)
AttributeError: 'NoneType' object has no attribute 'append'

# Fixed code
def add_lb_backend_address_pool_address(
    cmd,
    resource_group_name,
    load_balancer_name,
    backend_address_pool_name,
    address_name,
    vnet,
    ip_address,
):
    client = network_client_factory(cmd.cli_ctx).load_balancer_backend_address_pools
    address_pool = client.get(
        resource_group_name, load_balancer_name, backend_address_pool_name
    )
    (LoadBalancerBackendAddress, VirtualNetwork) = cmd.get_models(
        "LoadBalancerBackendAddress", "VirtualNetwork"
    )
    new_address = LoadBalancerBackendAddress(
        name=address_name,
        virtual_network=VirtualNetwork(id=vnet) if vnet else None,
        ip_address=ip_address if ip_address else None,
    )
    if address_pool.load_balancer_backend_addresses is None:
        address_pool.load_balancer_backend_addresses = []
    address_pool.load_balancer_backend_addresses.append(new_address)
    return client.create_or_update(
        resource_group_name, load_balancer_name, backend_address_pool_name, address_pool
    )