-
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
dbt 0.21.0-b2: test aliases don't play well with anchored yaml #3815
Comments
Oy! Thanks for opening @joellabes. I wouldn't consider this a true bug / blocke. At the same time, I totally appreciate the desire to keep using YAML anchors and have dynamic, sensible, non-colliding aliases. The really cool answer probably looks like supporting - name: hubspot_revenue__revenue_lines
columns:
- name: total_unweighted
tests: &revenue_range_tests
- not_null
- accepted_range:
alias: "{{ model }}__{{ column_name }}_not_below_0"
where: "is_resub_adjustment is false"
min_value: 0
tags:
- hubspot_bad_revenue
- accepted_range:
alias: "{{ model }}__{{ column_name }}_resub_adjustments_not_above_0"
where: "is_resub_adjustment is true"
max_value: 0
tags:
- hubspot_bad_revenue
- name: resub_unweighted
tests: *revenue_range_tests
- name: resub_weighted
tests: *revenue_range_tests
- name: sale_unweighted
tests: *revenue_range_tests
- name: sale_weighted
tests: *revenue_range_tests @gshank had the idea of creating a special rendering context to support this. I think it's a pretty good idea, and I'd like to revisit it around the time that we add support for generic test descriptions, too. In the meantime, I'm trying to think if there are potential workarounds that allow you to keep your anchors:
{% test test_accepted_range(model, column_name, min_value=none, max_value=none, inclusive=true) %}
{% set min_qualifier = 'not_below_' + min_value if min_value else '' %}
{% set max_qualifier = 'not_above_' + max_value if max_value else '' %}
{% set my_alias_rule = model + '__' + column_name + '_' + min_qualifier + max_qualifier %}
{{ config(alias = my_alias_rule) }}
... rest of test definition ...
{% endtest %} This almost works... except that, in an attempt to be helpful, we're checking the length of each specific test's alias, and overriding it with the shorter hash if it's too long, before the generic test definition's Let's think about whether there's a different place we can do this, so that an
{% macro generate_alias_name(custom_alias_name=none, node=none) -%}
{%- if custom_alias_name is none -%}
{{ node.name }}
{%- elif node.resource_type == 'test' -%}
{# for tests only, prepend the custom alias with column_name #}
{% set column_name = node.test_metadata.kwargs.column_name %}
{{ column_name }}__{{ custom_alias_name | trim }}
{%- else -%}
{{ custom_alias_name | trim }}
{%- endif -%}
{%- endmacro %} This one actually works today, it just feels pretty bad. |
Yes this sounds great! Happy to settle for non-anchor life and wait for the right-er approach, I'm pretty conservative on rolling out hacky workarounds 💤 Appreciate your help coming up with options though! |
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. |
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. |
At #3626 (comment), @jtcohen6 suggested:
I gave it a go, and realised that hardcoded aliases collide with anchored YAML such as this:
Which gives the unsurprising error:
Knowing as I do that anchors are pretty inflexible, I don't think I have much choice other than to swap the templated code out for a bunch more copy-pasted stuff, right?
The text was updated successfully, but these errors were encountered: