has_unique_tests
Rule: has_unique_test
has_unique_test details
This rule ensures that dbt objects (models, sources, etc.) have at least one uniqueness test attached to them. By default, it recognizes the standard
unique test and dbt_utils.unique_combination_of_columns and dbt_expectations.expect_compound_columns_to_be_unique, but can be configured to accept custom uniqueness test names.Configuration
- type: Must be
has_unique_test. - applies_to: (optional) List of dbt object types to include.
- Default:
["models", "sources"] - Options:
models,sources,seeds,snapshots
- Default:
- allowed_test_names: (optional) List of test names that qualify as uniqueness tests.
- Default:
["unique", "dbt_utils.unique_combination_of_columns", "dbt_expectations.expect_compound_columns_to_be_unique"] - Accepts any custom test names (e.g.,
["unique", "my_custom_unique_test"])
- Default:
Common Rule Config
- name: Human-readable name of the rule.
- severity:
"error"(fail) or"warning"(warn only).- (optional, defaults to
"error"if not specified)
- (optional, defaults to
- description: Human-readable explanation of the rule.
- category: Override the default rule category. Included in structured output (JSON, CSV, NDJSON) but not in the CLI table. Each rule has a built-in default (e.g.
documentation,naming,testing,governance,structure,performance).- (optional, defaults to the rule type's built-in category)
- includes: List of patterns to explicitly include for this rule. See Includes & Excludes for pattern syntax and examples.
- excludes: List of patterns to explicitly exclude from this rule. See Includes & Excludes for pattern syntax and examples.
- model_materializations: Filter models by materialization type. Only applies when
applies_toincludesmodels.- (optional, if not specified all materializations are included)
- Built-in types:
table,view,incremental,ephemeral,materialized_view. Custom materializations are also supported. - Example:
["table", "incremental"]
Example Config
manifest_tests:
- name: "models_should_have_unique_test"
type: "has_unique_test"
description: "All models should have a unique test"
severity: "error"
applies_to: ["models"]
# allowed_test_names: ["unique", "dbt_utils.unique_combination_of_columns"] (optional)
# includes: ["path/to/include/*"] (optional)
# excludes: ["path/to/exclude/*"] (optional)
- name: "sources_should_have_unique_test"
type: "has_unique_test"
description: "All sources must have uniqueness validation"
severity: "warning"
applies_to: ["sources"]
allowed_test_names:
- "unique"
- "dbt_utils.unique_combination_of_columns"
- "my_custom_unique_test"[[manifest_tests]]
name = "models_should_have_unique_test"
type = "has_unique_test"
description = "All models should have a unique test"
severity = "error"
applies_to = ["models"]
# allowed_test_names = ["unique", "dbt_utils.unique_combination_of_columns"] # (optional)
# includes = ["path/to/include/*"] # (optional)
# excludes = ["path/to/exclude/*"] # (optional)
[[manifest_tests]]
name = "sources_should_have_unique_test"
type = "has_unique_test"
description = "All sources must have uniqueness validation"
severity = "warning"
applies_to = ["sources"]
allowed_test_names = [
"unique",
"dbt_utils.unique_combination_of_columns",
"my_custom_unique_test"
][[tool.dbtective.manifest_tests]]
name = "models_should_have_unique_test"
type = "has_unique_test"
description = "All models should have a unique test"
severity = "error"
applies_to = ["models"]
# allowed_test_names = ["unique", "dbt_utils.unique_combination_of_columns"] # (optional)
# includes = ["path/to/include/*"] # (optional)
# excludes = ["path/to/exclude/*"] # (optional)
[[tool.dbtective.manifest_tests]]
name = "sources_should_have_unique_test"
type = "has_unique_test"
description = "All sources must have uniqueness validation"
severity = "warning"
applies_to = ["sources"]
allowed_test_names = [
"unique",
"dbt_utils.unique_combination_of_columns",
"my_custom_unique_test"
]Relevant dbt code
models:
- name: model_with_unique_tests
tests:
# dbt_utils built-in uniqueness test
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- customer_id
- order_id
columns:
- name: customer_id
tests:
- unique # dbt built-in uniqueness test
- my_custom_unique_test # Custom uniqueness test