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

Can't filter dbt nodes by tags when using LoadMode.CUSTOM #1367

Open
yoshimaru46 opened this issue Dec 6, 2024 · 3 comments · May be fixed by #1387
Open

Can't filter dbt nodes by tags when using LoadMode.CUSTOM #1367

yoshimaru46 opened this issue Dec 6, 2024 · 3 comments · May be fixed by #1387
Labels
area:selector Related to selector, like DAG selector, DBT selector, etc

Comments

@yoshimaru46
Copy link

yoshimaru46 commented Dec 6, 2024

issue

when using LoadMode.CUSTOM, tags passed to DbtNode is prefixed with tags:.

tags = [selector for selector in model.config.config_selectors if selector.startswith("tags:")]
node = DbtNode(
unique_id=f"{model.type.value}.{self.project.project_name}.{model_name}",
resource_type=DbtResourceType(model.type.value),
depends_on=list(model.config.upstream_models),
file_path=Path(
model.path.as_posix().replace(
self.render_config.project_path.as_posix(), self.execution_config.project_path.as_posix()
)
),
tags=tags or [],

therefore, _is_tags_subset become always false.

if not (set(self.config.tags) <= set(node.tags)):

How to reproduce

model.sql

config(tags=["foo"])

render_config

select=["tag:foo"],

_is_tags_subset

  • self.config.tags: set(["foo"])
  • node.tags: set(["tags:foo"])

(set(self.config.tags) <= set(node.tags)) => always false

@yoshimaru46 yoshimaru46 changed the title can't filter dbt node by tags when using LoadMode.CUSTOM Can't filter dbt node by tags when using LoadMode.CUSTOM Dec 6, 2024
@yoshimaru46 yoshimaru46 changed the title Can't filter dbt node by tags when using LoadMode.CUSTOM Can't filter dbt nodes by tags when using LoadMode.CUSTOM Dec 6, 2024
Copy link

dosubot bot commented Dec 6, 2024

Hey @yoshimaru46! 👋 I'm here to help you with any bugs, questions, or contributions you have. Let's squash those bugs together!

To resolve the issue where the _is_tags_subset function always returns false due to tags being prefixed with tags: when using LoadMode.CUSTOM, you need to modify the _is_tags_subset function to strip the tags: prefix from the node's tags before performing the subset check. Here's how you can adjust the function:

def _is_tags_subset(self, node: DbtNode) -> bool:
    """Checks if the node's tags are a subset of the config's tags."""
    # Remove 'tags:' prefix from node tags if present
    node_tags = [tag[len('tags:'):] if tag.startswith('tags:') else tag for tag in node.tags]
    if not (set(self.config.tags) <= set(node_tags)):
        return False
    return True

This modification ensures that the tags are compared correctly, allowing the subset check to function as intended [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot dosubot bot added the area:selector Related to selector, like DAG selector, DBT selector, etc label Dec 6, 2024
@pankajastro
Copy link
Contributor

Hey @yoshimaru46, would you like to submit a fix?

@yoshimaru46 yoshimaru46 linked a pull request Dec 12, 2024 that will close this issue
2 tasks
@yoshimaru46
Copy link
Author

yoshimaru46 commented Dec 12, 2024

PR: #1387 (WIP)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:selector Related to selector, like DAG selector, DBT selector, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants