[X] I have searched the existing issues, and I could not find an existing issue for this bug
Current Behavior
Unit tests fail if an input reference is a versioned model even though it is explicitly defined in both the model & the unit test input. The following is the error when the test fails:
Compilation Error in unit_test unit_test_mart__model_b (models/mart/unit_test.yml) Unit_Test 'unit_test.repo.mart__model_b.unit_test_mart__model_b’ (models/mart/unit_test.yml) depends on a node named ‘input_versioned_model’ which was not found
Expected Behavior
Unit test should run with specified versioned model.
Steps To Reproduce
Create a model with at least 1 version and have it saved with _v#, e.g. input_versioned_model_v1
This input_versioned_model_v1 has model.yml configured with latest_version: 1
Code for reference:
Create mart__model_b that references this input_versioned_model without the versioning
Code for reference:
with iv as (
select *
from
{{ ref('input_versioned_model') }}
),
im as (
select *
from
{{ ref('input_model2') }}
)
select
iv.id,
iv.category,
im.profile_id,
im.type
from
iv
join im
on iv.id = im.customer_id
mart__model_b builds correctly with dbt build -s +mart__model_b
Create a dbt unit test for mart__model_b
Code for reference:
Note: I tried the following versioned inputs:
`input: ref('input_versioned_model', v='1')`
`-input: ref('input_versioned_model', v=1)`
7. Run `dbt test --select "mart__model_b,test_type:unit"` will give you the following error:
`Compilation Error in unit_test unit_test_mart__model_b (models/mart/unit_test.yml)
Unit_Test 'unit_test.repo.mart__model_b.unit_test_mart__model_b’ (models/mart/unit_test.yml) depends on a node named ‘input_versioned_model’ which was not found`
### Relevant log output
```shell
`Compilation Error in unit_test unit_test_mart__model_b (models/mart/unit_test.yml)
Unit_Test 'unit_test.repo.mart__model_b.unit_test_mart__model_b’ (models/mart/unit_test.yml) depends on a node named ‘input_versioned_model’ which was not found`
Is this a new bug in dbt-core?
Current Behavior
Unit tests fail if an input reference is a versioned model even though it is explicitly defined in both the model & the unit test input. The following is the error when the test fails:
Compilation Error in unit_test unit_test_mart__model_b (models/mart/unit_test.yml) Unit_Test 'unit_test.repo.mart__model_b.unit_test_mart__model_b’ (models/mart/unit_test.yml) depends on a node named ‘input_versioned_model’ which was not found
Expected Behavior
Unit test should run with specified versioned model.
Steps To Reproduce
Create a model with at least 1 version and have it saved with
_v#
, e.g. input_versioned_model_v1This input_versioned_model_v1 has model.yml configured with
latest_version: 1
Code for reference:Create mart__model_b that references this input_versioned_model without the versioning Code for reference:
mart__model_b builds correctly with
dbt build -s +mart__model_b
Create a dbt unit test for mart__model_b Code for reference:
Environment
Which database adapter are you using with dbt?
redshift: 1.8.1
Additional Context
Found following github issues that are related: 10528 and 10623 and tried the solutions provided.