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

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

Closed
graciegoheen opened this issue Apr 3, 2024 · 3 comments
Labels
awaiting_response bug Something isn't working stale Issues that have gone stale

Comments

@graciegoheen
Copy link
Contributor

          @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 #9686 (comment)

@graciegoheen graciegoheen added triage bug Something isn't working labels Apr 3, 2024
@graciegoheen
Copy link
Contributor Author

Hi @kd-nishanth - moved this conversation over to a new issue as I don't think this is related to the ephemeral model problem. The direct parents of the model that you’re unit testing (in your example, anything model_a depends on - source_b and model_c) need to exist in the warehouse before you can execute the unit test, because we need to know what field names and data types to use when constructing the unit test sql.

Given that:

  • your source_b does exist on the database and is dbt profile is able to read from it
  • the unit test works if you swap out source_b with a table materialized model of source_b in the unit test and the model for model_a

this is quite perplexing!

Could you do two things:

  • check if you're able to run dbt docs generate for source_b
  • send an example of what your source yml definition looks like for source_b

Copy link
Contributor

github-actions bot commented Jul 3, 2024

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

@github-actions github-actions bot added the stale Issues that have gone stale label Jul 3, 2024
Copy link
Contributor

Although we are closing this issue as stale, it's not gone forever. Issues can be reopened if there is renewed community interest. Just add a comment to notify the maintainers.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting_response bug Something isn't working stale Issues that have gone stale
Projects
None yet
Development

No branches or pull requests

1 participant