EN

When dbt tests pass and revenue is still wrong

A dbt incremental model skipped a late correction even though its key tests passed. Reproduce the watermark bug and trace the stale row with DuckDB.

Order 42 still showed $100.00 after a late correction changed it to $75.00. Both dbt key tests passed on the persisted table. Each order had a unique, non-null key. In this synthetic fixture, the stale amount overstated revenue by $25.00.

Batch 2 check Result
dbt unique and not_null tests Both passed
Persisted incremental amount for order 42 $100.00
Amount for order 42 in the clean rebuild $75.00
Revenue overstatement in the fixture $25.00

Why the watermark missed the correction

Order 42 had been loaded at $100.00. Order 43 established the target table’s high-water mark at 2026-03-10 12:00:00. The next snapshot delivered order 42’s correction with that same update timestamp. The incremental filter required a strictly greater timestamp, so the correction never reached the merge. Starting snapshot · Corrected snapshot

and updated_at > (
  select coalesce(max(updated_at), timestamp '1970-01-01')
  from {{ this }}
)

A uniqueness test can find a duplicate order, and a non-null test can find a missing key. Here order 42 remained in the table once, with its original amount. The correction exposed a gap in the condition that decides which rows reach the merge. Model SQL

How to reproduce the missed update

Incremental Replay runs the model over the snapshots while retaining the incremental target. At each checked batch it also rebuilds from an empty database. Both runs use the same source snapshot and scenario clock.

From the repository root, with uv installed, run each command separately:

uv sync --locked --python 3.12
uv run --locked python examples/missed-update/check_keys.py
uv run --locked dbt-replay check examples/missed-update/scenario.yml

The key tests pass. The replay exits with code 1 and reports:

PASS step 01  initial orders
FAIL step 02  correction ties the high-water mark
First checked divergence: step 02 (correction ties the high-water mark)
  1 changed keys, 1 additional rows, 1 missing rows
  order_id=42

The additional row is the stale version of order 42, with amount_cents=10000. The missing row is its corrected version, with amount_cents=7500. Batch 2 tells you which input to inspect. Order 42 tells you which row to trace through the watermark filter.

Verify the repair

The repaired model keeps the same snapshot clock and changes the incremental filter. Inside the is_incremental() branch, it adds this predicate to the source query:

and not exists (
    select 1 from {{ this }} as previous
    where previous.order_id = src.order_id
      and previous.order_date is not distinct from src.order_date
      and previous.updated_at is not distinct from src.updated_at
      and previous.amount_cents is not distinct from src.amount_cents
)

Order 42 is visible at the batch clock. Its previous amount was 10000, so the target has no matching row with the corrected payload of 7500. The correction reaches the merge even though its timestamp ties the table’s watermark. An identical row is skipped on a retry. Working model

uv run --locked dbt-replay check examples/missed-update/fixed.yml

The repaired run exits with code 0 and agrees with the rebuild at both checkpoints. This filter can read more source and target rows than a timestamp watermark because it compares visible rows by key and payload. Measure that cost on your warehouse and adapter before using it on a large table.

The demo uses synthetic CSVs, DuckDB, and one deterministic current-state dbt model. Agreement means the persisted results matched on those snapshots at the checked batches. A transformation error shared by both paths can still pass. Run the walkthrough