Recency test to fail when no recent records are found #1051
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
resolves #1041
Problem
The
dbt_utils.recency
test incorrectly passes when awhere
clause filtersout all records.
Current behavior: When a
where
clause results in no matching records,most_recent
becomesNULL
. The test only checkswhere most_recent < {{ threshold }}
, but sinceNULL < threshold
evaluates toNULL
(not true), norows are returned and the test incorrectly passes.
Expected behavior: The test should fail when no recent data exists (even
when filtered by a where clause), indicating missing recent data.
Solution
Modified the
recency
macro inmacros/generic_tests/recency.sql
to includeor most_recent is null
in the WHERE clause. This ensures that when a whereclause filters out all records (causing
most_recent
to be null), the testcorrectly fails by returning the null row.
Changes made:
where most_recent < {{ threshold }}
towhere most_recent < {{ threshold }} or most_recent is null
recency_with_where_filter
that reproduces theoriginal bug and verifies the fix
filters to non-existent records
Testing approach:
most_recent
)Checklist
issue which has been
triaged and [accepted for development](https://docs.getdbt.com/docs/contributin
g/oss-expectations#pull-requests).
guide and
understand what's expected of me
issue