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-3387] [Bug] downstream model's tests are triggered together when it uses source() or ref() in tests referring upstream models. #9083

Closed
4 of 7 tasks
rightx2 opened this issue Nov 15, 2023 · 2 comments
Labels
bug Something isn't working wontfix Not a bug or out of scope for dbt-core

Comments

@rightx2
Copy link

rightx2 commented Nov 15, 2023

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

Describe the bug

  1. sources.yaml
version: 2

sources:
  - name: my_source
    tables:
      - name: raw_customers
        columns:
          - name: id
            tests:
              - not_null               
      - name: raw_payments
  1. models/schema.yaml
version: 2

models:
  - name: stg_customers
    columns:
      - name: customer_id
        tests:
          - relationships:
              to: source('my_source', 'raw_customers')
              field: id

When I run dbt test --select source:my_source.raw_customers, it trigger TWO TESTS, not one test:

  • relationships_stg_customers_customer_id__id__source_my_source_raw_customers_
  • source_not_null_my_source_raw_customers_id

Expected Behavior

Only source_not_null_my_source_raw_customers_id run.

Steps To Reproduce

Explained above

Relevant log output

INFO - �[0m05:12:44  1 of 2 START test relationships_stg_customers_customer_id__id__source_my_source_raw_customers_  [RUN]
INFO - �[0m05:12:44  1 of 2 ERROR relationships_stg_customers_customer_id__id__source_my_source_raw_customers_  [�[31mERROR�[0m in 0.01s]
INFO - �[0m05:12:44  2 of 2 START test source_not_null_my_source_raw_customers_id ................... [RUN]
INFO - �[0m05:12:44  2 of 2 PASS source_not_null_my_source_raw_customers_id ......................... [�[32mPASS�[0m in 0.02s]
INFO - �[0m05:12:44

Environment

Which database are you using dbt with?

  • postgres
  • redshift
  • bigquery
  • snowflake
  • other (specify: impala)

The output of dbt --version:

- dbt=1.6.6
- dbt-postgres==1.6.6

Which database adapter are you using with dbt?

No response

Additional Context

The reason might be that source('my_source', 'raw_customers') is used in stg_customers model's test..right?
But I don't understand why... I targeted just source, not downstream models.

Is there any way to make it test run only source_not_null_my_source_raw_customers_id when running dbt test --select source:my_source.raw_customers?

@rightx2 rightx2 added bug Something isn't working triage labels Nov 15, 2023
@github-actions github-actions bot changed the title [Bug] downstream model's tests are triggered together when it uses source() or ref() in tests referring upstream models. [CT-3387] [Bug] downstream model's tests are triggered together when it uses source() or ref() in tests referring upstream models. Nov 15, 2023
@dbeatty10
Copy link
Contributor

Is there any way to make it test run only source_not_null_my_source_raw_customers_id when running dbt test --select source:my_source.raw_customers?

There is! You're looking for indirect selection.

Wanna give that a try and see if it works for you?

Examples

For example, you can try using either the "buildable" or "cautious" modes to not "eagerly" select so many downstream tests.

Buildable is my preferred indirect selection:

dbt test --select source:my_source.raw_customers --indirect-selection buildable

It's possible to set this via an environment variable like this (assuming a shell like zsh or bash:

export DBT_INDIRECT_SELECTION=buildable

But cautious is another option you can use as well:

dbt test --select source:my_source.raw_customers --indirect-selection cautious

You can read all the details here.

Note

  • Until #7518 is resolved, there is not a global config for indirect_selection to set this in profiles.yml
  • Until #7673 is resolved, selectors default to eager regardless of the CLI flag or environment variable

@rightx2
Copy link
Author

rightx2 commented Nov 16, 2023

@dbeatty10 Exactly what I want! Thanks :)

@rightx2 rightx2 closed this as completed Nov 16, 2023
@dbeatty10 dbeatty10 added wontfix Not a bug or out of scope for dbt-core and removed triage labels Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix Not a bug or out of scope for dbt-core
Projects
None yet
Development

No branches or pull requests

2 participants