diff --git a/.changes/unreleased/Fixes-20230922-223313.yaml b/.changes/unreleased/Fixes-20230922-223313.yaml new file mode 100644 index 00000000000..3caf1cf2f96 --- /dev/null +++ b/.changes/unreleased/Fixes-20230922-223313.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Fixes test type edges filter +time: 2023-09-22T22:33:13.200662+02:00 +custom: + Author: renanleme + Issue: "8692" diff --git a/core/dbt/graph/graph.py b/core/dbt/graph/graph.py index 3bacba1ffc1..94747036fd4 100644 --- a/core/dbt/graph/graph.py +++ b/core/dbt/graph/graph.py @@ -1,6 +1,7 @@ from typing import Set, Iterable, Iterator, Optional, NewType from itertools import product import networkx as nx # type: ignore +from functools import partial from dbt.exceptions import DbtInternalError @@ -42,16 +43,14 @@ def descendants(self, node: UniqueId, max_depth: Optional[int] = None) -> Set[Un return {child for _, child in nx.bfs_edges(filtered_graph, node, depth_limit=max_depth)} def exclude_edge_type(self, edge_type_to_exclude): - return nx.restricted_view( + return nx.subgraph_view( self.graph, - nodes=[], - edges=( - (a, b) - for a, b in self.graph.edges - if self.graph[a][b].get("edge_type") == edge_type_to_exclude - ), + filter_edge=partial(self.filter_edges_by_type, edge_type=edge_type_to_exclude), ) + def filter_edges_by_type(self, first_node, second_node, edge_type): + return self.graph.get_edge_data(first_node, second_node).get("edge_type") != edge_type + def select_childrens_parents(self, selected: Set[UniqueId]) -> Set[UniqueId]: ancestors_for = self.select_children(selected) | selected return self.select_parents(ancestors_for) | ancestors_for