Skip to content

Commit

Permalink
Fix tag: selection for projects with semantic models (#8750)
Browse files Browse the repository at this point in the history
* Add unit test to repro regression

* Add defensive code for tag: selection

* Add changelog entry
  • Loading branch information
jtcohen6 authored Sep 29, 2023
1 parent 416bc84 commit 48c97e8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230929-175342.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix tag selection for projects with semantic models
time: 2023-09-29T17:53:42.960596+02:00
custom:
Author: jtcohen6
Issue: "8749"
4 changes: 3 additions & 1 deletion core/dbt/graph/selector_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ class TagSelectorMethod(SelectorMethod):
def search(self, included_nodes: Set[UniqueId], selector: str) -> Iterator[UniqueId]:
"""yields nodes from included that have the specified tag"""
for node, real_node in self.all_nodes(included_nodes):
if any(fnmatch(tag, selector) for tag in real_node.tags):
if hasattr(real_node, "tags") and any(
fnmatch(tag, selector) for tag in real_node.tags
):
yield node


Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_graph_selector_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,21 @@ def test_select_semantic_model(manifest):
assert search_manifest_using_method(manifest, method, "*omer") == {"customer"}


def test_select_semantic_model_by_tag(manifest):
semantic_model = make_semantic_model(
"pkg",
"customer",
model="customers",
path="_semantic_models.yml",
)
manifest.semantic_models[semantic_model.unique_id] = semantic_model
methods = MethodManager(manifest, None)
method = methods.get_method("tag", [])
assert isinstance(method, TagSelectorMethod)
assert method.arguments == []
search_manifest_using_method(manifest, method, "any_tag")


@pytest.fixture
def previous_state(manifest):
writable = copy.deepcopy(manifest).writable_manifest()
Expand Down

0 comments on commit 48c97e8

Please sign in to comment.