Skip to content

Commit 3e8a7aa

Browse files
authored
Add rule: prevent use of is_incremental() in non-incremental models (#103)
(note: changelog has been updated by mistake and already reflects this pull request)
1 parent d16d067 commit 3e8a7aa

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/dbt_score/rules/generic.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,23 @@ def has_uniqueness_test(model: Model) -> RuleViolation | None:
100100
pk_columns = model_constraint.columns or []
101101
break
102102

103-
if not pk_columns: # No PK, no need for uniqueness test
103+
if not pk_columns: # No PK, no need for uniqueness test
104104
return None
105105

106106
for data_test in model.tests:
107107
if data_test.type == "unique_combination_of_columns":
108-
if set(data_test.kwargs.get("combination_of_columns")) == set(pk_columns): # type: ignore
108+
if set(data_test.kwargs.get("combination_of_columns")) == set(pk_columns): # type: ignore
109109
return None
110110
return RuleViolation(
111111
f"No uniqueness test defined and matching PK {','.join(pk_columns)}."
112112
)
113+
114+
115+
@rule(rule_filters={is_table()})
116+
def has_no_unused_is_incremental(model: Model) -> RuleViolation | None:
117+
"""Non-incremental model does not make use of is_incremental()."""
118+
if (
119+
model.config.get("materialized") != "incremental"
120+
and "is_incremental()" in model.raw_code
121+
):
122+
return RuleViolation("Non-incremental model makes use of is_incremental().")

0 commit comments

Comments
 (0)