Skip to content

[Bug] hard_deletes='new_record' not working when strategy='check' #11269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 tasks done
paritoshg2010 opened this issue Feb 4, 2025 · 5 comments
Open
2 tasks done
Labels
bug Something isn't working snapshots Issues related to dbt's snapshot functionality
Milestone

Comments

@paritoshg2010
Copy link

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

In dbt-core 1.9, with dbt snapshot new feature to capture the new records for the deleted items, I have noticed that if the deleted records are restored, those are not reinserted in snapshot table.

snapshot config:

strategy='check',

hard_deletes= 'new_record'

As you see in the attached screenshot, the deleted record entry is the last entry in this table.

Image

Expected Behavior

Once the records are restored, the deleted entry (is_deleted='True') in snapshot table should be invalidated and the new record will be created.

Steps To Reproduce

  1. Run dbt snapshot on any table, to replicate all the records from monitored table.
  2. Now delete one record from monitored table & run the dbt snapshot on that table. There will be new entry created for the deleted record with the previous one getting invalidated and the new one with dbt_is_deleted='True'.
  3. Now again try to restore that delete record in the monitored table, and run the dbt snapshot on it. The new entry for the restored item is not getting create in snapshot table.

Relevant log output

Environment

- OS: macOS Sonoma ver 14.6.1
- Python: 3.11.8
- dbt-core: 1.9.1
- dbt-adapters: dbt-snowflake 1.9

Which database adapter are you using with dbt?

snowflake

Additional Context

No response

@paritoshg2010 paritoshg2010 added bug Something isn't working triage labels Feb 4, 2025
@paritoshg2010 paritoshg2010 changed the title [Bug] <title> Restored deleted items are not appearing in dbt Snapshots 1.9 [Bug] Restored deleted items are not appearing in dbt Snapshots 1.9 Feb 4, 2025
@dbeatty10 dbeatty10 added the snapshots Issues related to dbt's snapshot functionality label Mar 4, 2025
@graciegoheen graciegoheen added this to the v1.10 milestone Mar 15, 2025
@graciegoheen
Copy link
Contributor

Hi - thanks for opening. The test coverage we have is for using hard_deletes='new_record' with strategy='timestamp'. I'm wondering if this is specifically a bug for the strategy='check'.

@paritoshg2010
Copy link
Author

Hi - thanks for opening. The test coverage we have is for using hard_deletes='new_record' with strategy='timestamp'. I'm wondering if this is specifically a bug for the strategy='check'.

Hey Grace, Thanks for replying. I did specifically faced this issue with the 'check' strategy. Wondering if this is resolved in v1.10 ?

@graciegoheen
Copy link
Contributor

Not yet, but I will have one of our engineers take a look and hopefully we can get this resolved before the final 1.10 release!

@graciegoheen graciegoheen changed the title [Bug] Restored deleted items are not appearing in dbt Snapshots 1.9 [Bug] hard_deletes='new_record' not working when strategy='check' Mar 28, 2025
@RB-Analytics
Copy link

Sorry to butt in but there's also a bug with the strategy = 'check' and the legacy invalidate_hard_deletes=True. Since dbt 1.9, the snapshot will no longer populate the field dbt_valid_to once it detects a deleted unique_key. It is now leaving them Null which means you get multiple valid values at a given point in time sadly. Has this been raised?

@jomach
Copy link

jomach commented Apr 17, 2025

Same issue here with dbt core 1.9.4. I'm building the id with a surrogate key based on all fields. After restoring the value the value on the column dbt_is_deleted is still true but it should be false as the record is valid again.

snapshots:
  - name: t_strc_parent
    relation: ref('parent_child')
    config:
      unique_key: id
      strategy: check
      check_cols:
        - id
      hard_deletes: new_record

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working snapshots Issues related to dbt's snapshot functionality
Projects
None yet
Development

No branches or pull requests

5 participants