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

[CT-468] [Feature] ref() should be treated as model parent in generic test arguments #5006

Closed
1 task done
jarno-r opened this issue Apr 7, 2022 · 1 comment
Closed
1 task done
Labels
dbt tests Issues related to built-in dbt testing functionality duplicate This issue or pull request already exists enhancement New feature or request node selection Functionality and syntax for selecting DAG nodes

Comments

@jarno-r
Copy link

jarno-r commented Apr 7, 2022

Is there an existing feature request for this?

  • I have searched the existing issues

Describe the Feature

A generic test can have an argument that is a reference to another table. For example:

models:
  - name: my_model
    tests:
      - is_equal:
          compare_to: ref('other_model')

dbt build --select +my_model should also include other_model in the DAG.

Not including other_model as a parent may also cause build failures due to other_model being build after my_model when running dbt build --select my_model other_model.

Describe alternatives you've considered

A ref() could be used in my_model.sql in a dummy set statement:

{% set _ = ref('outer_model') %}

This requires having the reference in two places and does not work with seeds.

Who will this benefit?

Anyone who wishes to use generic tests that refer to other models. These are particularly useful in unit testing macros.

Are you interested in contributing this feature?

No response

Anything else?

No response

@jarno-r jarno-r added enhancement New feature or request triage labels Apr 7, 2022
@github-actions github-actions bot changed the title [Feature] ref() should be treated as model parent in generic test arguments [CT-468] [Feature] ref() should be treated as model parent in generic test arguments Apr 7, 2022
@jtcohen6
Copy link
Contributor

jtcohen6 commented Apr 7, 2022

@jarno-r Thanks for opening!

This is a complex edge case, and one that's come up many times before. We went on an epic journey related to this exact question last year: #2874, #2891, #4082

Two things are at play here:

  • Technically, other_model is not a parent node of my_model, but they are both parents of a common child node (the is_equal test). So other_model is not included by +my_model
  • The is_equal test is selected by +my_model, as it would be my_model, because tests are selected indirectly and eagerly by default. That is, when you say "build my model," that also means "run any tests that depend on my model."

You have two valid options:

  1. Use the @ operator instead of the + operator, i.e. dbt build --select @my_model. This means: Build this model, its parents, its children, and other parents of its children. https://docs.getdbt.com/reference/node-selection/graph-operators#the-at-operator
  2. Switch "indirect selection" for tests from "eager" to "cautious." Eager means, run any tests with at least one selected parent. "Cautious" means, don't run any test with at least one unselected parent. https://docs.getdbt.com/reference/node-selection/test-selection-examples#indirect-selection

This is a complex problem, and we found it impossible to define a default behavior that accounts for every scenario. That's where configuration comes in. At it is, I feel pretty happy with where we've landed on this one, so I'm going to close this issue.

@jtcohen6 jtcohen6 added duplicate This issue or pull request already exists dbt tests Issues related to built-in dbt testing functionality node selection Functionality and syntax for selecting DAG nodes Team:Execution and removed triage labels Apr 7, 2022
@jtcohen6 jtcohen6 closed this as completed Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dbt tests Issues related to built-in dbt testing functionality duplicate This issue or pull request already exists enhancement New feature or request node selection Functionality and syntax for selecting DAG nodes
Projects
None yet
Development

No branches or pull requests

2 participants