Commit 11f7cf7
Fix: hard_deletes invalidate incorrectly invalidating active records in snapshots (#1283)
Resolves #1281
### Description
When running a snapshot with `hard_deletes: invalidate`, records that
still exist in the source table were being incorrectly marked as
invalidated.
**Root Cause:** The `when not matched by source` clause (introduced in
1.11.1) matches unchanged records because the staging table only
contains *changed* records, not all records.
**Solution:** Removed the `when not matched by source` clause. The
existing `deletes` CTE already properly handles deletions via
`dbt_change_type = 'delete'` and the correct `dbt_scd_id`.
We reproduced and verified the fix using the exact example provided in
the issue.
**Tested on:** SQL Warehouse with Unity Catalog
### Checklist
- [x] I have run this code in development and it appears to resolve the
stated issue
- [x] This PR includes tests, or tests are not required/relevant for
this PR
- [x] I have updated the `CHANGELOG.md` and added information about my
change to the "dbt-databricks next" section.
---------
Signed-off-by: Stefan Zurborg <stefan.zurborg@fielmann.com>
Co-authored-by: Ben Cassell <98852248+benc-db@users.noreply.github.com>1 parent 955743a commit 11f7cf7
3 files changed
Lines changed: 19 additions & 12 deletions
File tree
- dbt/include/databricks/macros/materializations
- tests/functional/adapter/simple_snapshot
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
5 | 8 | | |
6 | 9 | | |
7 | 10 | | |
| |||
Lines changed: 0 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | 33 | | |
41 | 34 | | |
42 | 35 | | |
| |||
Lines changed: 15 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
170 | 171 | | |
| 172 | + | |
171 | 173 | | |
172 | | - | |
173 | | - | |
174 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
175 | 178 | | |
176 | | - | |
| 179 | + | |
177 | 180 | | |
178 | 181 | | |
179 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
180 | 190 | | |
181 | 191 | | |
| 192 | + | |
182 | 193 | | |
183 | 194 | | |
184 | 195 | | |
| |||
0 commit comments