dbt-utils icon indicating copy to clipboard operation
dbt-utils copied to clipboard

Issue in recency test when using where in the config

Open marzaccaro opened this issue 3 months ago • 0 comments

Describe the bug

When using dbt_utils.recency test in combination with the config: where parameter to limit the scanned data the test will pass if no record is found to be less than the threshold - so the test is passing if no recent data are found!

Steps to reproduce

example seed (example.csv)

ingestion_date
2024-10-01
2025-01-01

test configuration on the seed (ie _seeds.yml)

seeds:
  - name: example
     tests:
       - dbt_utils.recency:
            arguments:
              datepart: day
              field: ingestion_date
              interval: 1
              config: 
                where: "ingestion_date > current_date - 2"

Expected results

I would expect this to fail the tests (as it happens when there is no filters)

Actual results

The test is actually passing!

Screenshots and log output

System information

The contents of your packages.yml file:

packages:
  - package: dbt-labs/dbt_utils
    version: 1.3.0

Which database are you using dbt with?

  • [ ] postgres
  • [ ] redshift
  • [X] bigquery
  • [X] snowflake
  • [ ] other (specify: ____________)

The output of dbt --version:

Latest of dbt 

Additional context

The reason for the issue is we have this where clause here https://github.com/dbt-labs/dbt-utils/blob/31382da621330401e5bac528ac31a4dd2dd43cdc/macros/generic_tests/recency.sql#L39 we should have something like this:

where most_recent < {{ threshold }} or most_recent is null

Are you interested in contributing the fix?

Yes happy to contribute to the fix, will try to open a PR for this :)

marzaccaro avatar Sep 04 '25 14:09 marzaccaro