dbt source not being found in dbt run

Viewed 39

thank you for your help in advance. I'm using dbt and am at the point in the jaffle_shop tutorial to set up sources. I set up everything as the tutorial states and everything has been working up until now.

File tree

jaffle_shop
  - models
    - marts/core
      - dim_customers.sql
      - fct_orders.sql
    - staging/jaffle_shop
      - stg_customers.sql
      - stg_orders.sql
      - stg_payments.sql
      - src_jaffle_shop.yml
  - dbt_project.yml

The src_jaffle_shop.yml looks like this:

version: 2

sources:
  - name: jaffle_shop
    schema: dbt_jallard
    database: dhaus
    tables:
      - name: customers
      - name: orders
      - name: payment

An example of the staging files is this:

with customers as (

    select
        id as customer_id,
        first_name,
        last_name

    from {{ source('dbt_jallard','customers') }}
    -- from dbt_jallard.customers

)

select * from customers 

As you can see I commented out the regular sql from-statement. When using that statement it works as intended, but when I try using the source() reference, I get this error:

Model 'model.jaffle_shop.stg_customers' (models/staging/jaffle_shop/stg_customers.sql) depends on a source named 'dbt_jallard.customers' which was not found

The database is configured correctly because it works when calling from dbt_jallard.customers but for some reason using {{ source('dbt_jallard','customers') }} gives this error.

Any insight would be helpful. Thank you!

3 Answers

Can you please replace jaffle_shop with dbt_jallard as name in source yml file

You've named your source 'jaffle_shop' in your src_jaffle_shop.yml file. The syntax for a Jinja source reference in dbt is {{ source(source_name, table_name)}}. Thus, this error message is telling you it can't find a source with source_name dbt_jallard table_name customers because there isn't one.

Please review the documentation here for more detail.

Changing your source reference to {{ source('jaffle_shop','customers')}} will resolve your issue.

I had to change the source() function to refer to the name of the source rather than the database name.

{{ source("jaffle_shop","customers") }}

Related