Skip to content

Rules that operate on multiple resource types #115

@ross-whatnot

Description

@ross-whatnot

As more types of evaluable are covered by dbt-score, I'm increasingly finding that I'm writing somewhat repetitive tests to cover different evaluable types; for a simple example, imagine:

@rule
def model_is_not_beta(model: Model) -> RuleViolation | None:
    if 'beta' in model.tags:
        return RuleViolation(f"{model.name} is beta, which isn't allowed")
    return None

@rule
def snapshot_is_not_beta(snapshot: Snapshot) -> RuleViolation | None:
    if 'beta' in snapshot.tags:
        return RuleViolation(f"{snapshot.name} is beta, which isn't allowed")
    return None

There remain a lot of cases where I do want type specific tests, but there are also cases where I'm validating properties that are common across multiple types of evaluable. I find myself wondering about being able to define a rule like:

@rule
def resource_is_not_beta(resource: Model | Snapshot) -> RuleViolation | None:
    if 'beta' in resource.tags:
        return RuleViolation(f"{resource.name} is beta, which isn't allowed")
    return None

That would feel like it still allows the rule writer control over what types of evaluable a rule is executed on, but also allow "common" rules to run on multiple evaluable types. I don't think this works like this today, but curious if this feels like a productive direction?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions