Skip to content
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

Snapshot config doesn't work in schema.yml #4000

Closed
Tracked by #10151
gshank opened this issue Oct 4, 2021 · 10 comments · Fixed by #10275
Closed
Tracked by #10151

Snapshot config doesn't work in schema.yml #4000

gshank opened this issue Oct 4, 2021 · 10 comments · Fixed by #10275
Assignees
Labels
snapshots Issues related to dbt's snapshot functionality user docs [docs.getdbt.com] Needs better documentation

Comments

@gshank
Copy link
Contributor

gshank commented Oct 4, 2021

Validation is performed on SnapshotConfig objects when the snapshot node is parsed/created. This validation means that config must be set in the sql file and can't be set in the schema file.

To allow setting in schema files we would need to defer validation until after schema file parsing.

@gshank gshank changed the title Snapshot config don't work in schema.yml Snapshot config doesn't work in schema.yml Oct 4, 2021
@jtcohen6
Copy link
Contributor

jtcohen6 commented Oct 5, 2021

@gshank Ah! I now remember noticing this at one point, too. Thanks for keeping track of it and opening the issue.

The validation currently occurs within the validate method of SnapshotConfig, and I'm guessing that occurs before patching. Do you have a sense of where we could move the validation so that it happens post-patching?

@jtcohen6 jtcohen6 added the snapshots Issues related to dbt's snapshot functionality label Oct 5, 2021
@gshank
Copy link
Contributor Author

gshank commented Oct 5, 2021

It would have to happen as a post-schema-file parsing step, at about the same place in the manifest parser where we handle updating docs and refs.

@gshank
Copy link
Contributor Author

gshank commented Oct 12, 2021

Error message for this:
Encountered an error:
Snapshots must be configured with a 'strategy', 'unique_key', and 'target_schema'.

@github-actions
Copy link
Contributor

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please remove the stale label or comment on the issue, or it will be closed in 7 days.

@github-actions github-actions bot added the stale Issues that have gone stale label May 20, 2022
@github-actions
Copy link
Contributor

Although we are closing this issue as stale, it's not gone forever. Issues can be reopened if there is renewed community interest; add a comment to notify the maintainers.

@jtcohen6 jtcohen6 removed the stale Issues that have gone stale label Sep 16, 2022
@jtcohen6
Copy link
Contributor

Reopening this one as it's still relevant. Possibly related to the work Emily was just doing around models set to enabled: false in config .yml files (#5869)

@jtcohen6
Copy link
Contributor

jtcohen6 commented Sep 16, 2022

In the meantime, a functional workaround that I don't feel great about:

# dbt_project.yml
snapshots:
  # set defaults here to avoid validation errors during first parse
  strategy: check_cols
  unique_key: id
  target_schema: "{{ target.schema }}"

Then all snapshots will have the default values set when first parsed, allowing me to set snapshot-specific properties in other .yml files instead.

-- snapshots/my_snap.sql
{% snapshot my_snapshot() %}

    select
        1 as specific_id,
        current_timestamp as updated_at
        
{% endsnapshot %}
# snapshots/config.yml
version: 2
snapshots:
  - name: my_snapshot
    config:
      target_schema: specific_schema
      unique_key: specific_id
      strategy: timestamp
      updated_at: updated_at

Downside: If you forget to set those properties individually, for a real snapshot, you'll only find out at runtime.

Copy link
Contributor

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

@github-actions github-actions bot added the stale Issues that have gone stale label Feb 26, 2024
Copy link
Contributor

github-actions bot commented Mar 5, 2024

Although we are closing this issue as stale, it's not gone forever. Issues can be reopened if there is renewed community interest. Just add a comment to notify the maintainers.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 5, 2024
@gshank gshank reopened this May 20, 2024
@graciegoheen graciegoheen added user docs [docs.getdbt.com] Needs better documentation and removed stale Issues that have gone stale labels May 28, 2024
@FishtownBuildBot
Copy link
Collaborator

Opened a new issue in dbt-labs/docs.getdbt.com: dbt-labs/docs.getdbt.com#5627

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
snapshots Issues related to dbt's snapshot functionality user docs [docs.getdbt.com] Needs better documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants