dbt-labs / dbt-core

dbt enables data analysts and engineers to transform their data using the same practices that software engineers use to build applications.
https://getdbt.com
Apache License 2.0
10.01k stars 1.63k forks source link

[Bug] Unit tests don't recognize versioned sources #11039

Open gnilrets opened 3 days ago

gnilrets commented 3 days ago

Is this a new bug in dbt-core?

Current Behavior

I have a test that depends on a model that is versioned, but when I run the test, I get an error that the node cannot be found.

For example, in my unit test I have:

unit_tests:
  - name: test_fct_nerc_core__unpatched
    model: fct_nerc_core__unpatched

    given:
      - input: ref('fct_outage')
        # blah....

The fct_outage model is versioned, and I removed the v1 version a while ago, so I just have:

fct_outage_v2.sql
fct_outage.yml

The fct_outage.yml model is defined as

models:
  - name: fct_outage
    latest_version: 2
   #....
    versions:
      - v: 2

When I run the unit test, I get:

23:22:59    Compilation Error in unit_test test_fct_nerc_core__unpatched (models/marts/customer/int/fct_nerc_core__unpatched.yml)
  Unit_Test 'unit_test.eta_wh.fct_nerc_core__unpatched.test_fct_nerc_core__unpatched' (models/marts/customer/int/fct_nerc_core__unpatched.yml) depends on a node named 'fct_outage' which was not found

However, if I remove versions from fct_outage.yml and rename fct_outage_v2.sql to fct_outage.sql, the unit test works.

Expected Behavior

We should be able to run unit tests that depend on models that are versioned.

Steps To Reproduce

  1. Create a unit test for a model that depends on a versioned model.
  2. Run the unit test.

Relevant log output

No response

Environment

- OS: Debian GNU/Linux 12 (bookworm)
- Python: Python 3.10.15
- dbt: 1.8.5

Which database adapter are you using with dbt?

snowflake

Additional Context

No response

dbeatty10 commented 1 day ago

Thanks for reaching out @gnilrets !

We just merged https://github.com/dbt-labs/dbt-core/pull/10889 a little over a week ago, and it will be included in dbt-core v1.9, and it looks to me like it would solve the issue you are reporting here.

Here are the other descriptions of the issue:

Could you give these a look and see if they describe the same thing that you experienced?

gnilrets commented 9 hours ago

That's it. I missed those bugs because I was only searching for open bugs. Thanks!