Skip to content

Commit

Permalink
Merge pull request #89 from nicholasyager/nicholasyager-limit_resourc…
Browse files Browse the repository at this point in the history
…e_types_access_controls

Fix: `ResourceGrouper` no longer considers `test` resources during access control inference step
  • Loading branch information
dave-connors-3 authored Jul 5, 2023
2 parents 6935d1f + b0cb70e commit 91427bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion dbt_meshify/utilities/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def classify_resource_access(cls, graph, nodes):
}
return resources

@classmethod
def clean_subgraph(cls, graph: networkx.DiGraph) -> networkx.DiGraph:
"""Generate a subgraph that does not contain test resource types."""
test_nodes = set(node for node in graph.nodes if node.startswith('test'))
return graph.subgraph(set(graph.nodes) - test_nodes)

def _generate_resource_group(
self,
name: str,
Expand Down Expand Up @@ -96,7 +102,8 @@ def _generate_resource_group(
f"of the {existing_group} group. Please remove {node} from its group and try again."
)

resources = self.classify_resource_access(self.project.graph.graph, nodes)
cleaned_subgraph = self.clean_subgraph(self.project.graph.graph)
resources = self.classify_resource_access(cleaned_subgraph, nodes)

return group, resources

Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_resource_grouper_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ def example_graph(self):
graph.add_edges_from([("a", "b"), ("b", "c"), ("b", "d"), ("d", "1")])
return graph

@pytest.fixture
def example_graph_with_tests(self):
graph = networkx.DiGraph()
graph.add_edges_from(
[
("source.a", "model.b"),
("model.b", "test.c"),
("model.b", "model.d"),
("model.d", "test.1"),
]
)
return graph

def test_resource_grouper_boundary_classification(self, example_graph):
nodes = {"a", "b", "c", "d"}
resources = ResourceGrouper.classify_resource_access(example_graph, nodes)
Expand All @@ -22,3 +35,7 @@ def test_resource_grouper_boundary_classification(self, example_graph):
"c": AccessType.Public,
"d": AccessType.Public,
}

def test_clean_graph_removes_test_nodes(self, example_graph_with_tests):
output_graph = ResourceGrouper.clean_subgraph(example_graph_with_tests)
assert set(output_graph.nodes) == {"source.a", "model.b", "model.d"}

0 comments on commit 91427bc

Please sign in to comment.