Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Test model with data that's intentionally old
-- This simulates a scenario where we have data but it's all outside the recency window
-- this should fail with a where clause but currently it would pass
select
1 as id,
{{ dbt.dateadd('day', -10, dbt.current_timestamp()) }} as created_at

union all

select
2 as id,
{{ dbt.dateadd('day', -15, dbt.current_timestamp()) }} as created_at
16 changes: 16 additions & 0 deletions integration_tests/models/generic_tests/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,19 @@ models:
compare_model: ref('data_test_equality_a')
exclude_columns:
- col_c

- name: recency_with_where_filter
data_tests:
# This test should FAIL and return 0 rows (test failure) because when we filter to id = 3,
# no records match the where condition, so most_recent will be null.
# Before the fix: test would incorrectly PASS (no rows returned)
# After the fix: test should correctly FAIL (returns the null row)
- dbt_utils.recency:
datepart: day
field: created_at
ignore_time_component: true
interval: 5
config:
where: "id = 3" # This filters to no records since only id 1,2 exist
error_if: "<1"
warn_if: "<0"
1 change: 1 addition & 0 deletions macros/generic_tests/recency.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ select

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

{% endmacro %}
Loading