diff --git a/.changes/unreleased/Fixes-20230929-175342.yaml b/.changes/unreleased/Fixes-20230929-175342.yaml new file mode 100644 index 00000000000..190e3a26588 --- /dev/null +++ b/.changes/unreleased/Fixes-20230929-175342.yaml @@ -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" diff --git a/core/dbt/graph/selector_methods.py b/core/dbt/graph/selector_methods.py index 57d559aa606..520c4df3c52 100644 --- a/core/dbt/graph/selector_methods.py +++ b/core/dbt/graph/selector_methods.py @@ -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 diff --git a/tests/unit/test_graph_selector_methods.py b/tests/unit/test_graph_selector_methods.py index 94153159640..49c4c86219e 100644 --- a/tests/unit/test_graph_selector_methods.py +++ b/tests/unit/test_graph_selector_methods.py @@ -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()