# Buggy code
def get_generic_get_iter(
    self, call, attribute=None, field=None, query=None, children="attributes-list"
):
    generic_call = self.call_api(call, query)

    if field is None:
        out = []
    else:
        out = {}

    attributes_list = generic_call.get_child_by_name(children)

    if attributes_list is None:
        return None

    for child in attributes_list.get_children():
        d = xmltodict.parse(child.to_string(), xml_attribs=False)

        if attribute is not None:
            d = d[attribute]

        if isinstance(field, str):
            unique_key = _finditem(d, field)
            out = out.copy()
            out.update({unique_key: convert_keys(json.loads(json.dumps(d)))})
        elif isinstance(field, tuple):
            unique_key = ":".join([_finditem(d, el) for el in field])
            out = out.copy()
            out.update({unique_key: convert_keys(json.loads(json.dumps(d)))})
        else:
            out.append(convert_keys(json.loads(json.dumps(d))))

    return out


# Traceback (TypeError)
TASK [Test_gather] **************************************************************************************************************************************************************************************************************************
task path: /git/devel/gather_system.yml:21
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~root &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1536039256.01-6248969617936 `" &amp;&amp; echo ansible-tmp-1536039256.01-6248969617936="` echo /root/.ansible/tmp/ansible-tmp-1536039256.01-6248969617936 `" ) &amp;&amp; sleep 0'
Using module file /home/centos/ansible2.6/lib/python2.7/site-packages/ansible/modules/storage/netapp/na_ontap_gather_facts.py
<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-26695H5a1l7/tmpw3CAow TO /root/.ansible/tmp/ansible-tmp-1536039256.01-6248969617936/na_ontap_gather_facts.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1536039256.01-6248969617936/ /root/.ansible/tmp/ansible-tmp-1536039256.01-6248969617936/na_ontap_gather_facts.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/home/centos/ansible2.6/bin/python /root/.ansible/tmp/ansible-tmp-1536039256.01-6248969617936/na_ontap_gather_facts.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1536039256.01-6248969617936/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_eHzOnQ/ansible_module_na_ontap_gather_facts.py", line 295, in <module>
main()
File "/tmp/ansible_eHzOnQ/ansible_module_na_ontap_gather_facts.py", line 289, in main
g = v.get_all()
File "/tmp/ansible_eHzOnQ/ansible_module_na_ontap_gather_facts.py", line 199, in get_all
query={'max-records': '1024'}
File "/tmp/ansible_eHzOnQ/ansible_module_na_ontap_gather_facts.py", line 156, in get_generic_get_iter
unique_key = ':'.join([_finditem(d, el) for el in field])
TypeError: sequence item 1: expected string or Unicode, NoneType found

fatal: [localhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_eHzOnQ/ansible_module_na_ontap_gather_facts.py\", line 295, in <module>\n    main()\n  File \"/tmp/ansible_eHzOnQ/ansible_module_na_ontap_gather_facts.py\", line 289, in main\n    g = v.get_all()\n  File \"/tmp/ansible_eHzOnQ/ansible_module_na_ontap_gather_facts.py\", line 199, in get_all\n    query={'max-records': '1024'}\n  File \"/tmp/ansible_eHzOnQ/ansible_module_na_ontap_gather_facts.py\", line 156, in get_generic_get_iter\n    unique_key = ':'.join([_finditem(d, el) for el in field])\nTypeError: sequence item 1: expected string or Unicode, NoneType found\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}

# Fixed code
def get_generic_get_iter(
    self, call, attribute=None, field=None, query=None, children="attributes-list"
):
    generic_call = self.call_api(call, query)

    if generic_call is None:
        return None

    if field is None:
        out = []
    else:
        out = {}

    attributes_list = generic_call.get_child_by_name(children)

    if attributes_list is None:
        return None

    for child in attributes_list.get_children():
        d = xmltodict.parse(child.to_string(), xml_attribs=False)

        if attribute is not None:
            d = d[attribute]

        if isinstance(field, str):
            unique_key = _finditem(d, field)
            out = out.copy()
            out.update({unique_key: convert_keys(json.loads(json.dumps(d)))})
        elif isinstance(field, tuple):
            unique_key = ":".join([_finditem(d, el) for el in field])
            out = out.copy()
            out.update({unique_key: convert_keys(json.loads(json.dumps(d)))})
        else:
            out.append(convert_keys(json.loads(json.dumps(d))))

    return out