# Buggy code
def _construct_url_3(self, root, parent, obj, child_includes):
    """
    This method is used by get_url when the object is the third-level class.
    """
    root_rn = root["aci_rn"]
    root_obj = root["module_object"]
    parent_class = parent["aci_class"]
    parent_rn = parent["aci_rn"]
    parent_filter = parent["filter_target"]
    parent_obj = parent["module_object"]
    obj_class = obj["aci_class"]
    obj_rn = obj["aci_rn"]
    obj_filter = obj["filter_target"]
    mo = obj["module_object"]

    if not child_includes:
        self_child_includes = "&rsp-subtree=full&rsp-subtree-class=" + obj_class
    else:
        self_child_includes = "{0},{1}".format(child_includes, obj_class)

    if not child_includes:
        parent_self_child_includes = (
            "&rsp-subtree=full&rsp-subtree-class={0},{1}".format(
                parent_class, obj_class
            )
        )
    else:
        parent_self_child_includes = "{0},{1},{2}".format(
            child_includes, parent_class, obj_class
        )

    # State is ablsent or present
    if self.module.params["state"] != "query":
        path = "api/mo/uni/{0}/{1}/{2}.json".format(root_rn, parent_rn, obj_rn)
        filter_string = "?rsp-prop-include=config-only" + child_includes
    # Query for all objects of the module's class
    elif mo is None and parent_obj is None and root_obj is None:
        path = "api/class/{0}.json".format(obj_class)
        filter_string = ""
    # Queries when root object is provided
    elif root_obj is not None:
        # Queries when parent object is provided
        if parent_obj is not None:
            # Query for a specific object of the module's class
            if mo is not None:
                path = "api/mo/uni/{0}/{1}/{2}.json".format(root_rn, parent_rn, obj_rn)
                filter_string = ""
            # Query for all objects of the module's class that belong to a specific parent object
            else:
                path = "api/mo/uni/{0}/{1}.json".format(root_rn, parent_rn)
                filter_string = self_child_includes.replace("&", "?", 1)
        # Query for all objects of the module's class that match the provided ID value and belong to a specefic root object
        elif mo is not None:
            path = "api/mo/uni/{0}.json".format(root_rn)
            filter_string = "?rsp-subtree-filter={0}{1}".format(
                obj_filter, self_child_includes
            )
        # Query for all objects of the module's class that belong to a specific root object
        else:
            path = "api/mo/uni/{0}.json".format(root_rn)
            filter_string = "?" + parent_self_child_includes
    # Queries when parent object is provided but root object is not provided
    elif parent_obj is not None:
        # Query for all objects of the module's class that belong to any parent class
        # matching the provided ID values for both object and parent object
        if mo is not None:
            path = "api/class/{0}.json".format(parent_class)
            filter_string = "?query-target-filter={0}{1}&rsp-subtree-filter={2}".format(
                parent_filter, self_child_includes, obj_filter
            )
        # Query for all objects of the module's class that belong to any parent class
        # matching the provided ID value for the parent object
        else:
            path = "api/class/{0}.json".format(parent_class)
            filter_string = "?query-target-filter={1}{2}".format(
                parent_filter, self_child_includes
            )
    # Query for all objects of the module's class matching the provided ID value of the object
    else:
        path = "api/class/{0}.json".format(obj_class)
        filter_string = "?query-target-filter={0}".format(obj_filter) + child_includes

    # append child_includes to filter_string if filter string is empty
    if child_includes is not None and filter_string == "":
        filter_string = child_includes.replace("&", "?", 1)

    return path, filter_string


# Traceback (IndexError)
TASK [aci_bd_subnet : get all in bd] ******************************************************************************************************************************************************************************
task path: /home/dag/home-made/ansible.git/test/integration/targets/aci_bd_subnet/tasks/main.yml:126
Using module file /home/dag/home-made/ansible.git/lib/ansible/modules/network/aci/aci_bd_subnet.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: dag
<127.0.0.1> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/dag/.ansible/tmp/ansible-tmp-1516475732.33-191885580229472 `" &amp;&amp; echo ansible-tmp-1516475732.33-191885580229472="` echo /home/dag/.ansible/tmp/ansible-tmp-1516475732.33-191885580229472 `" ) &amp;&amp; sleep 0'
<127.0.0.1> PUT /home/dag/.ansible/tmp/ansible-local-211245wJGDF/tmpC1Zc83 TO /home/dag/.ansible/tmp/ansible-tmp-1516475732.33-191885580229472/aci_bd_subnet.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/dag/.ansible/tmp/ansible-tmp-1516475732.33-191885580229472/ /home/dag/.ansible/tmp/ansible-tmp-1516475732.33-191885580229472/aci_bd_subnet.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/tmp/ansible-test-coverage-TjwnOo/coverage/injector.py /home/dag/.ansible/tmp/ansible-tmp-1516475732.33-191885580229472/aci_bd_subnet.py &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_dTLgAO/ansible_module_aci_bd_subnet.py", line 333, in <module>
main()
File "/tmp/ansible_dTLgAO/ansible_module_aci_bd_subnet.py", line 296, in main
child_classes=['fvRsBDSubnetToProfile', 'fvRsNdPfxPol'],
File "/tmp/ansible_dTLgAO/ansible_modlib.zip/ansible/module_utils/network/aci/aci.py", line 378, in construct_url
File "/tmp/ansible_dTLgAO/ansible_modlib.zip/ansible/module_utils/network/aci/aci.py", line 525, in _construct_url_3
IndexError: tuple index out of range

fatal: [localhost]: FAILED! => {
"attempts": 1,
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_dTLgAO/ansible_module_aci_bd_subnet.py\", line 333, in <module>\n    main()\n  File \"/tmp/ansible_dTLgAO/ansible_module_aci_bd_subnet.py\", line 296, in main\n    child_classes=['fvRsBDSubnetToProfile', 'fvRsNdPfxPol'],\n  File \"/tmp/ansible_dTLgAO/ansible_modlib.zip/ansible/module_utils/network/aci/aci.py\", line 378, in construct_url\n  File \"/tmp/ansible_dTLgAO/ansible_modlib.zip/ansible/module_utils/network/aci/aci.py\", line 525, in _construct_url_3\nIndexError: tuple index out of range\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}
to retry, use: --limit @/home/dag/home-made/ansible.git/test/integration/aci_bd_subnet-6tRWH_.retry

PLAY RECAP ********************************************************************************************************************************************************************************************************
localhost                  : ok=14   changed=5    unreachable=0    failed=1

# Fixed code
def _construct_url_3(self, root, parent, obj, child_includes):
    """
    This method is used by get_url when the object is the third-level class.
    """
    root_rn = root["aci_rn"]
    root_obj = root["module_object"]
    parent_class = parent["aci_class"]
    parent_rn = parent["aci_rn"]
    parent_filter = parent["filter_target"]
    parent_obj = parent["module_object"]
    obj_class = obj["aci_class"]
    obj_rn = obj["aci_rn"]
    obj_filter = obj["filter_target"]
    mo = obj["module_object"]

    if not child_includes:
        self_child_includes = "&rsp-subtree=full&rsp-subtree-class=" + obj_class
    else:
        self_child_includes = "{0},{1}".format(child_includes, obj_class)

    if not child_includes:
        parent_self_child_includes = (
            "&rsp-subtree=full&rsp-subtree-class={0},{1}".format(
                parent_class, obj_class
            )
        )
    else:
        parent_self_child_includes = "{0},{1},{2}".format(
            child_includes, parent_class, obj_class
        )

    # State is ablsent or present
    if self.module.params["state"] != "query":
        path = "api/mo/uni/{0}/{1}/{2}.json".format(root_rn, parent_rn, obj_rn)
        filter_string = "?rsp-prop-include=config-only" + child_includes
    # Query for all objects of the module's class
    elif mo is None and parent_obj is None and root_obj is None:
        path = "api/class/{0}.json".format(obj_class)
        filter_string = ""
    # Queries when root object is provided
    elif root_obj is not None:
        # Queries when parent object is provided
        if parent_obj is not None:
            # Query for a specific object of the module's class
            if mo is not None:
                path = "api/mo/uni/{0}/{1}/{2}.json".format(root_rn, parent_rn, obj_rn)
                filter_string = ""
            # Query for all objects of the module's class that belong to a specific parent object
            else:
                path = "api/mo/uni/{0}/{1}.json".format(root_rn, parent_rn)
                filter_string = self_child_includes.replace("&", "?", 1)
        # Query for all objects of the module's class that match the provided ID value and belong to a specefic root object
        elif mo is not None:
            path = "api/mo/uni/{0}.json".format(root_rn)
            filter_string = "?rsp-subtree-filter={0}{1}".format(
                obj_filter, self_child_includes
            )
        # Query for all objects of the module's class that belong to a specific root object
        else:
            path = "api/mo/uni/{0}.json".format(root_rn)
            filter_string = "?" + parent_self_child_includes
    # Queries when parent object is provided but root object is not provided
    elif parent_obj is not None:
        # Query for all objects of the module's class that belong to any parent class
        # matching the provided ID values for both object and parent object
        if mo is not None:
            path = "api/class/{0}.json".format(parent_class)
            filter_string = "?query-target-filter={0}{1}&rsp-subtree-filter={2}".format(
                parent_filter, self_child_includes, obj_filter
            )
        # Query for all objects of the module's class that belong to any parent class
        # matching the provided ID value for the parent object
        else:
            path = "api/class/{0}.json".format(parent_class)
            filter_string = "?query-target-filter={0}{1}".format(
                parent_filter, self_child_includes
            )
    # Query for all objects of the module's class matching the provided ID value of the object
    else:
        path = "api/class/{0}.json".format(obj_class)
        filter_string = "?query-target-filter={0}".format(obj_filter) + child_includes

    # append child_includes to filter_string if filter string is empty
    if child_includes is not None and filter_string == "":
        filter_string = child_includes.replace("&", "?", 1)

    return path, filter_string