def select_parents(
        self, selected: Set[UniqueId], max_depth: Optional[int] = None
    ) -> Set[UniqueId]:
        """Returns all nodes which are ancestors of the 'selected' set.
        Nodes in the 'selected' set are counted as parents only if
        they are ancestors of other nodes in the 'selected' set."""
        parents: Set[UniqueId] = set()
        i = 0
        while len(selected) > 0 and (max_depth is None or i < max_depth):
            next_layer: Set[UniqueId] = set()
            for node in selected:
                next_layer.update(
                    iter(
                        e[0]
                        for e in self.graph.in_edges(node)
                        if e[0] not in parents
                        and self.filter_edges_by_type(e[0], e[1], "parent_test")
                    )
                )
            parents.update(next_layer)
            selected = next_layer
            i += 1

        return parents
Returns all nodes which are ancestors of the 'selected' set.
        Nodes in the 'selected' set are counted as parents only if
        they are ancestors of other nodes in the 'selected' set.
core/dbt/graph/graph.py