dbt test failure (unique / not_null) fails CI with exit 1
A dbt data test found rows that violate its assertion (duplicates for a unique test, nulls for a not_null test). dbt reports the failing test and exits non-zero, which fails the CI job by design.
What this error means
dbt test or dbt build prints "Failure in test unique_orders_order_id" with a failing row count and ends with "Done. PASS=... ERROR=... FAIL=1" and exit code 1.
Failure in test not_null_orders_customer_id (models/marts/schema.yml)
Got 4 results, configured to fail if != 0
Done. PASS=12 WARN=0 ERROR=0 SKIP=0 TOTAL=13Common causes
The data genuinely violates the assertion
Real duplicates or nulls exist in the model, so the test correctly fails and blocks the pipeline.
The test is stricter than the data guarantees
A not_null or unique test asserts a property the source cannot guarantee, producing an expected but blocking failure.
How to fix it
Inspect the failing rows
- Run the test with
--store-failuresor read the compiled test SQL. - Query the failing rows to see the duplicates or nulls.
- Fix the model logic or the upstream data, then re-run the test.
dbt test --select orders --store-failuresAdjust severity if the test is advisory
If a failure should warn rather than block, set the test severity to warn instead of loosening data guarantees silently.
columns:
- name: customer_id
tests:
- not_null:
config:
severity: warnHow to prevent it
- Run
dbt buildin CI so tests gate model changes. - Use
--store-failuresto debug which rows violate a test. - Set severity intentionally: error to block, warn for advisory checks.