From 97686e13af9380f45bcf407596f7be8e41d23718 Mon Sep 17 00:00:00 2001 From: Renan Leme Date: Tue, 26 Sep 2023 15:55:45 +0200 Subject: [PATCH] CT-3144 Fix test edges type filter on Graph (#8696) * CT-3144 Fix test edges filter * CT-3144 Add changelog * CT-3144 Remove duplicated line * CT-3144 Remove duplicated line * CT-3144 Rename vars * CT-3144 Update filter to use get_edge_data * Trigger cla --- .changes/unreleased/Fixes-20230922-223313.yaml | 6 ++++++ core/dbt/graph/graph.py | 13 ++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 .changes/unreleased/Fixes-20230922-223313.yaml 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 69a2f21258a..633fa6d2079 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