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

[Bug] Unit test fails with versioned inputs #10880

Closed
2 tasks done
clairegchen opened this issue Oct 17, 2024 · 1 comment · Fixed by #10889
Closed
2 tasks done

[Bug] Unit test fails with versioned inputs #10880

clairegchen opened this issue Oct 17, 2024 · 1 comment · Fixed by #10889
Labels
bug Something isn't working model_versions unit tests Issues related to built-in dbt unit testing functionality

Comments

@clairegchen
Copy link

clairegchen commented Oct 17, 2024

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

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

  1. Create a model with at least 1 version and have it saved with _v#, e.g. input_versioned_model_v1
  2. This input_versioned_model_v1 has model.yml configured with latest_version: 1
    Code for reference:
  - name: input_versioned_model_v1 
    latest_version: 1
    columns:
      - name: id
        ...
    versions:
      - v: 1
  1. 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
  1. mart__model_b builds correctly with dbt build -s +mart__model_b
  2. Create a dbt unit test for mart__model_b
    Code for reference:
  - name: unit_test_mart__model_b
    model: mart__model_b
    given:
      - input: ref('input_versioned_model', v='1')
        rows:
        - {id: 123, category: electronics}
      - input: ref('input_model2')
        rows:
        - {customer_id: 123, profile_id: 2356, type: onetime}
    expect:
      rows:
      - {id: 123, category: electronics, profile_id: 2356, type: onetime}

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

`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`

Environment

- OS:
- Python: 3.12.6
- dbt-core: 1.8.3 & tried with 1.8.6 & 1.8.7
Plugins:
  - redshift: 1.8.1

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.

@clairegchen clairegchen added bug Something isn't working triage labels Oct 17, 2024
@dbeatty10 dbeatty10 added model_versions unit tests Issues related to built-in dbt unit testing functionality labels Oct 18, 2024
@devmessias
Copy link
Contributor

Have you tried this ?

with iv as (
    select *
    from
        {{ ref('input_versioned_model', v=1) }}
),

I found a problem with versioned refs that I was able to solve with #10889

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working model_versions unit tests Issues related to built-in dbt unit testing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants