-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Incorrect identifiers in snapshot schema test when overriding the ref() macro #2848
Comments
@MartinGuindon Thanks for the detailed writeup!
The reason here is simple: you use the I don't think we should make a dbt change here: if you construct your own
{% macro ref_snapshot(snapshot_name) %}
{% do return(builtins.ref(model_name)) %}
{% endmacro %} Use
{% macro ref(model_name) %}
{% if model_name.startswith('snap_') %}
{% do return(builtins.ref(model_name)) %}
{% else %}
{% do return(builtins.ref(model_name).include(database=false)) %}
{% endif %}
{% endmacro %} I'm going to close this, but I remain curious to hear what you think! |
Hi @jtcohen6, I'm confused. I'm not explicitly using the ref() function, as I'm not talking about a model leveraging a snapshot. If I were to use the ref() function in a model, pointing to a snapshot, I fully understand that it would be totally normal (and hence why snapshots tables are configured as sources prior to using them in models). I'm talking about defining a schema test like So option 1 is not possible. Option 2 works, I just tested it. However, I feel like this is a workaround and not a long term solution. Shouldn't schema tests set to a snapshot render properly to the configured database/schema, since those are not dynamic unlike the models? |
Wow! I'm sorry, I completely skipped over the fact that this is about schema tests. Let me re-open and think about this some more. |
@MartinGuindon Apologies again for misunderstanding your original issue. This is... tricky! I admit it feels a bit weird that overriding the builtin
In most projects, snapshots live in one or more stable, set-aside databases. Is that true in your case as well? Given that, here's the best answer I've got right now:
This worked when I tested it locally, running schema tests against snapshots configured with What I'd love to do here is make the conditional check |
@jtcohen6 I'd think that a special handling for snapshots would be ideal, but in the mean time using |
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. |
I'm going to close this out since we now support environment-aware snapshots |
Describe the bug
When overriding the ref() macro to render identifiers without a database (as documented here), schema tests defined for snapshots in a snapshot properties file are rendered without a database.
As snapshots are "static" based on the snapshot configuration and not environment-based, I'm a bit surprised about this behavior. I would have assumed that schema tests on snapshots would be unaffected by ref() override, just like schema tests on sources are unaffected.
I therefore assume that this is a bug.
Steps To Reproduce
Expected behavior
Schema tests for snapshots should ignore the ref() function configuration and simply point to the configured database/schema of the specific snapshot.
System information
Which database are you using dbt with?
The output of
dbt --version
:The operating system you're using:
MacOS 10.15.7
The output of
python --version
:Python 3.7.6
The text was updated successfully, but these errors were encountered: