Skip to content
Latchkey

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.

dbt
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=13

Common 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

  1. Run the test with --store-failures or read the compiled test SQL.
  2. Query the failing rows to see the duplicates or nulls.
  3. Fix the model logic or the upstream data, then re-run the test.
Terminal
dbt test --select orders --store-failures

Adjust 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.

models/marts/schema.yml
columns:
  - name: customer_id
    tests:
      - not_null:
          config:
            severity: warn

How to prevent it

  • Run dbt build in CI so tests gate model changes.
  • Use --store-failures to debug which rows violate a test.
  • Set severity intentionally: error to block, warn for advisory checks.

Frequently asked questions

What causes ""Failure in test ... unique / not_null""?
Real duplicates or nulls exist in the model, so the test correctly fails and blocks the pipeline.
How do I fix "Failure in test ... unique / not_null"?
Inspect the failing rows

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card