Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 1.6.latest] Fix tag: selection for projects with semantic models #8752

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading