Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Not able to get columns for source, when defining unit test on a model that depends on source #995

@graciegoheen

Description

@graciegoheen
          @graciegoheen sure

I have built a dbt model (say model_a) which targets a database _analysis and depends on source table source_b in the database _raw. The model builds fine so I know that the model's not buggy but the unit test fails with the following error:

Compilation Error in model source_b (models/source.yml)
Not able to get columns for unit test 'source_b' from relation "_raw"."public"."source_b"

> in macro get_fixture_sql (macros/unit_test_sql/get_fixture_sql.sql)
> called by model source_b (models/source.yml)
- name: test_model_a
    description: "Test model_a model"
    model: model_a
    given: 
      - input: source('_raw', 'source_b')
        rows:
          - ...
      - input: ref('model_c')
        rows:
          - ...
    expect:
      rows:
        - ...

Additional Information:

  • I don't have any unit tests defined for source_b
  • "_raw"."public"."source_b" does exist on the database and is dbt profile is able to read from it (because the model get's built)
  • the unit test works if I swap out source_b with a table materialized model of source_b in the unit test and the model for model_a.

I'm happy to share more and/or contribute to resolving this ticket.

Originally posted by @kd-nishanth in dbt-labs/dbt-core#9686 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature:unit-testsIssues related to built-in dbt unit testing functionalitytriage:producttype:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions