# Buggy code
def _toggle_delvol(
    name=None,
    instance_id=None,
    device=None,
    volume_id=None,
    value=None,
    requesturl=None,
):
    if not instance_id:
        instances = list_nodes_full(get_location())
        instance_id = instances[name]["instanceId"]

    if requesturl:
        data = query(requesturl=requesturl)
    else:
        params = {"Action": "DescribeInstances", "InstanceId.1": instance_id}
        data, requesturl = query(  # pylint: disable=W0632
            params, return_url=True
        )

    blockmap = data[0]["instancesSet"]["item"]["blockDeviceMapping"]

    params = {"Action": "ModifyInstanceAttribute", "InstanceId": instance_id}

    if type(blockmap["item"]) != list:
        blockmap["item"] = [blockmap["item"]]

    for idx, item in enumerate(blockmap["item"]):
        device_name = item["deviceName"]

        if device is not None and device != device_name:
            continue
        if volume_id is not None and volume_id != item["ebs"]["volumeId"]:
            continue

        params["BlockDeviceMapping.{0}.DeviceName".format(idx)] = device_name
        params["BlockDeviceMapping.{0}.Ebs.DeleteOnTermination".format(idx)] = value

    query(params, return_root=True)

    return query(requesturl=requesturl)


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python2.7/dist-packages/salt/cloud/__init__.py", line 1190, in create
output = self.clouds[func](vm_)
File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/ec2.py", line 2059, in create
call='action'
File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/ec2.py", line 2158, in create_attach_volumes
value=delvols_on_destroy)
File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/ec2.py", line 3020, in _toggle_delvol
return query(requesturl=requesturl)
File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/ec2.py", line 280, in query
params_with_headers = params.copy()
AttributeError: 'NoneType' object has no attribute 'copy'

# Fixed code
def _toggle_delvol(
    name=None,
    instance_id=None,
    device=None,
    volume_id=None,
    value=None,
    requesturl=None,
):
    if not instance_id:
        instances = list_nodes_full(get_location())
        instance_id = instances[name]["instanceId"]

    if requesturl:
        data = query(requesturl=requesturl)
    else:
        params = {"Action": "DescribeInstances", "InstanceId.1": instance_id}
        data, requesturl = query(  # pylint: disable=W0632
            params, return_url=True
        )

    blockmap = data[0]["instancesSet"]["item"]["blockDeviceMapping"]

    params = {"Action": "ModifyInstanceAttribute", "InstanceId": instance_id}

    if type(blockmap["item"]) != list:
        blockmap["item"] = [blockmap["item"]]

    for idx, item in enumerate(blockmap["item"]):
        device_name = item["deviceName"]

        if device is not None and device != device_name:
            continue
        if volume_id is not None and volume_id != item["ebs"]["volumeId"]:
            continue

        params["BlockDeviceMapping.{0}.DeviceName".format(idx)] = device_name
        params["BlockDeviceMapping.{0}.Ebs.DeleteOnTermination".format(idx)] = value

    query(params, return_root=True)

    kwargs = {"instance_id": instance_id, "device": device, "volume_id": volume_id}
    return show_delvol_on_destroy(name, kwargs, call="action")