Skip to content
Latchkey

dbt test "Failure ... got N results, expected 0" (unique) in CI

A dbt unique test found duplicate values in a column that is supposed to be unique. dbt reports the count of offending rows and fails because it is configured to fail when the result is not zero.

What this error means

A dbt test step fails with "Failure in test unique_<model>_<column> ... Got N results, configured to fail if != 0" for one or more models.

dbt
Failure in test unique_orders_order_id (models/marts/orders.yml)
  Got 7 results, configured to fail if != 0
  compiled Code at target/compiled/.../unique_orders_order_id.sql

Common causes

Duplicate keys in the model output

The transform produced repeated values in a column declared unique, often from a fan-out join or a missing dedup step.

The uniqueness assumption is wrong

The column is unique only in combination with another; a single-column unique test is the wrong constraint.

How to fix it

Inspect the failing rows and dedup

  1. Open the compiled test SQL that dbt printed and run it to see the duplicates.
  2. Fix the join or add a dedup so keys are unique.
  3. Re-run dbt build so the model is rebuilt before the test.
Terminal
dbt test --select unique_orders_order_id --store-failures

Use a combination uniqueness test

If uniqueness is over multiple columns, use dbt_utils.unique_combination_of_columns instead of a single-column test.

schema.yml
- dbt_utils.unique_combination_of_columns:
    combination_of_columns: [order_id, line_number]

How to prevent it

  • Run dbt build so models rebuild before tests in CI.
  • Use --store-failures to inspect offending rows.
  • Model composite keys with combination-uniqueness tests.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →