From ce4befdc9d332471a8ec9fd86a510e85cd4e746d Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Fri, 29 Sep 2023 18:49:32 +0200 Subject: [PATCH] Fix `tag:` selection for projects with semantic models (#8750) * Add unit test to repro regression * Add defensive code for tag: selection * Add changelog entry (cherry picked from commit 48c97e86dd2de4b60c8ef31b5a9d558d058d6690) --- .changes/unreleased/Fixes-20230929-175342.yaml | 6 ++++++ core/dbt/graph/selector_methods.py | 4 +++- tests/unit/test_graph_selector_methods.py | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Fixes-20230929-175342.yaml 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()