def get_descendants(actionexecution_id, descendant_depth=-1, result_fmt=None):
    """
    Returns all descendant executions upto the specified descendant_depth for
    the supplied actionexecution_id.
    """
    descendants = DESCENDANT_VIEWS.get(result_fmt, DFSDescendantView)()
    children = ActionExecution.query(
        parent=actionexecution_id, **{"order_by": ["start_timestamp"]}
    )
    LOG.debug("Found %s children for id %s.", len(children), actionexecution_id)
    current_level = [(child, 1) for child in children]

    while current_level:
        parent, level = current_level.pop(0)
        parent_id = str(parent.id)
        descendants.add(parent)
        if not parent.children:
            continue
        if level != -1 and level == descendant_depth:
            continue
        children = ActionExecution.query(
            parent=parent_id, **{"order_by": ["start_timestamp"]}
        )
        LOG.debug("Found %s children for id %s.", len(children), parent_id)
        # prepend for DFS
        for idx in range(len(children)):
            current_level.insert(idx, (children[idx], level + 1))
    return descendants.result

    Returns all descendant executions upto the specified descendant_depth for
    the supplied actionexecution_id.
    
st2common/st2common/services/executions.py