Skip to content

Commit 3d865af

Browse files
committed
resolve issue 1041
1 parent 7672637 commit 3d865af

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Test model with data that's intentionally old
2+
-- This simulates a scenario where we have data but it's all outside the recency window
3+
-- this should fail with a where clause but currently it would pass
4+
select
5+
1 as id,
6+
{{ dbt.dateadd('day', -10, dbt.current_timestamp()) }} as created_at
7+
8+
union all
9+
10+
select
11+
2 as id,
12+
{{ dbt.dateadd('day', -15, dbt.current_timestamp()) }} as created_at

integration_tests/models/generic_tests/schema.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,19 @@ models:
261261
compare_model: ref('data_test_equality_a')
262262
exclude_columns:
263263
- col_c
264+
265+
- name: recency_with_where_filter
266+
data_tests:
267+
# This test should FAIL and return 0 rows (test failure) because when we filter to id = 3,
268+
# no records match the where condition, so most_recent will be null.
269+
# Before the fix: test would incorrectly PASS (no rows returned)
270+
# After the fix: test should correctly FAIL (returns the null row)
271+
- dbt_utils.recency:
272+
datepart: day
273+
field: created_at
274+
ignore_time_component: true
275+
interval: 5
276+
config:
277+
where: "id = 3" # This filters to no records since only id 1,2 exist
278+
error_if: "<1"
279+
warn_if: "<0"

macros/generic_tests/recency.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ select
3737

3838
from recency
3939
where most_recent < {{ threshold }}
40+
or most_recent is null
4041

4142
{% endmacro %}

0 commit comments

Comments
 (0)