Skip to content

Commit d8ebe13

Browse files
Fix issue with check column snapshots in new_record mode. (#1068)
1 parent 5210a79 commit d8ebe13

File tree

11 files changed

+164
-46
lines changed

11 files changed

+164
-46
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Fixes
2+
body: Fix an issue with snapshots in new_record mode when check columns are used.
3+
time: 2025-05-06T15:03:45.057076-04:00
4+
custom:
5+
Author: peterallenwebb
6+
Issue: "1068"

dbt-adapters/src/dbt/include/global_project/macros/materializations/snapshots/helpers.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@
109109
left outer join snapshotted_data
110110
on {{ unique_key_join_on(strategy.unique_key, "snapshotted_data", "source_data") }}
111111
where {{ unique_key_is_null(strategy.unique_key, "snapshotted_data") }}
112-
or ({{ unique_key_is_not_null(strategy.unique_key, "snapshotted_data") }} and ({{ strategy.row_changed }})
112+
or ({{ unique_key_is_not_null(strategy.unique_key, "snapshotted_data") }} and (
113+
{{ strategy.row_changed }} {%- if strategy.hard_deletes == 'new_record' -%} or snapshotted_data.{{ columns.dbt_is_deleted }} = 'True' {% endif %}
114+
)
113115

114116
)
115117

@@ -129,7 +131,7 @@
129131
join snapshotted_data
130132
on {{ unique_key_join_on(strategy.unique_key, "snapshotted_data", "source_data") }}
131133
where (
132-
{{ strategy.row_changed }}
134+
{{ strategy.row_changed }} {%- if strategy.hard_deletes == 'new_record' -%} or snapshotted_data.{{ columns.dbt_is_deleted }} = 'True' {% endif %}
133135
)
134136
)
135137

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Under the Hood
2+
body: Expand snapshot testing.
3+
time: 2025-05-06T16:20:28.912537-04:00
4+
custom:
5+
Author: peterallenwebb
6+
Issue: "1068"

dbt-postgres/tests/functional/adapter/test_simple_snapshot.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from dbt.tests.adapter.simple_snapshot.new_record_check_mode import BaseSnapshotNewRecordCheckMode
2+
from dbt.tests.adapter.simple_snapshot.new_record_timestamp_mode import (
3+
BaseSnapshotNewRecordTimestampMode,
4+
)
15
from dbt.tests.adapter.simple_snapshot.test_snapshot import (
26
BaseSimpleSnapshot,
37
BaseSnapshotCheck,
@@ -10,3 +14,11 @@ class TestSnapshot(BaseSimpleSnapshot):
1014

1115
class TestSnapshotCheck(BaseSnapshotCheck):
1216
pass
17+
18+
19+
class TestSnapshotNewRecordTimestampMode(BaseSnapshotNewRecordTimestampMode):
20+
pass
21+
22+
23+
class TestSnapshotNewRecordCheckMode(BaseSnapshotNewRecordCheckMode):
24+
pass
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Under the Hood
2+
body: Expand snapshot testing.
3+
time: 2025-05-06T16:21:25.26162-04:00
4+
custom:
5+
Author: peterallenwebb
6+
Issue: "1068"

dbt-redshift/tests/functional/adapter/test_simple_snapshot.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from dbt.tests.adapter.simple_snapshot.new_record_check_mode import BaseSnapshotNewRecordCheckMode
2+
from dbt.tests.adapter.simple_snapshot.new_record_timestamp_mode import (
3+
BaseSnapshotNewRecordTimestampMode,
4+
)
15
from dbt.tests.adapter.simple_snapshot.test_snapshot import BaseSnapshotCheck, BaseSimpleSnapshot
26

37

@@ -7,3 +11,11 @@ class TestSnapshot(BaseSimpleSnapshot):
711

812
class TestSnapshotCheck(BaseSnapshotCheck):
913
pass
14+
15+
16+
class TestSnapshotNewRecordTimestampMode(BaseSnapshotNewRecordTimestampMode):
17+
pass
18+
19+
20+
class TestSnapshotNewRecordCheckMode(BaseSnapshotNewRecordCheckMode):
21+
pass
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Under the Hood
2+
body: Expand snapshot testing.
3+
time: 2025-05-06T16:20:55.476606-04:00
4+
custom:
5+
Author: peterallenwebb
6+
Issue: "1068"

dbt-snowflake/tests/functional/adapter/test_simple_snapshot.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
from dbt.tests.adapter.simple_snapshot.test_snapshot import BaseSnapshotCheck, BaseSimpleSnapshot
2+
from dbt.tests.adapter.simple_snapshot.new_record_timestamp_mode import (
3+
BaseSnapshotNewRecordTimestampMode,
4+
)
5+
from dbt.tests.adapter.simple_snapshot.new_record_check_mode import BaseSnapshotNewRecordCheckMode
26

37

48
class TestSnapshot(BaseSimpleSnapshot):
@@ -7,3 +11,11 @@ class TestSnapshot(BaseSimpleSnapshot):
711

812
class TestSnapshotCheck(BaseSnapshotCheck):
913
pass
14+
15+
16+
class TestSnapshotNewRecordTimestampMode(BaseSnapshotNewRecordTimestampMode):
17+
pass
18+
19+
20+
class TestSnapshotNewRecordCheckMode(BaseSnapshotNewRecordCheckMode):
21+
pass
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Under the Hood
2+
body: Add new tests for snapshots in new_record mode in combination with check columns.
3+
time: 2025-05-06T16:30:44.72145-04:00
4+
custom:
5+
Author: peterallenwebb
6+
Issue: "1068"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import pytest
2+
3+
from dbt.tests.adapter.simple_snapshot.new_record_timestamp_mode import (
4+
BaseSnapshotNewRecordTimestampMode,
5+
)
6+
7+
_snapshots_yml = """
8+
snapshots:
9+
- name: snapshot_actual
10+
config:
11+
strategy: check
12+
check_cols: all
13+
hard_deletes: new_record
14+
"""
15+
16+
_ref_snapshot_sql = """
17+
select * from {{ ref('snapshot_actual') }}
18+
"""
19+
20+
21+
class BaseSnapshotNewRecordCheckMode(BaseSnapshotNewRecordTimestampMode):
22+
@pytest.fixture(scope="class")
23+
def models(self):
24+
return {
25+
"snapshots.yml": _snapshots_yml,
26+
"ref_snapshot.sql": _ref_snapshot_sql,
27+
}

0 commit comments

Comments
 (0)