You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

dbt run时source未找到问题求助(jaffle_shop教程场景)

dbt source()引用报错排查方案

问题描述

直接使用from dbt_jallard.customers可以正常运行,但使用{{ source('dbt_jallard','customers') }}时触发错误:

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

核心排查步骤

  • 修正source()参数错误
    source()函数的第一个参数是source配置里的name字段值,而非schema名。你的src_jaffle_shop.yml中source名称是jaffle_shop,所以正确引用应为:

    from {{ source('jaffle_shop','customers') }}
    

    你之前错误地将schema dbt_jallard作为第一个参数传入,导致dbt找不到对应的source定义。

  • 核对source配置文件
    确认src_jaffle_shop.yml的配置逻辑:

    version: 2
    
    sources:
      - name: jaffle_shop  # 这是source的名称,对应source()的第一个参数
        schema: dbt_jallard # 这是数据库中的schema名
        database: dhaus
        tables:
          - name: customers
          - name: orders
          - name: payment # 注意:如果实际表名是payments,这里可能存在笔误
    
  • 验证dbt是否识别到source
    运行命令dbt source list,查看输出中是否包含jaffle_shop.customers。如果没有,检查配置文件路径是否在dbt扫描范围内(当前路径models/staging/jaffle_shop/src_jaffle_shop.yml符合默认扫描规则,一般没问题)。

  • 检查source渲染结果
    执行dbt compile --select stg_customers,查看target/compiled/jaffle_shop/models/staging/jaffle_shop/stg_customers.sql文件,确认source()是否被正确渲染为dhaus.dbt_jallard.customers(不同数据库的全限定名格式可能略有差异)。

附用户提供的文件信息

文件目录结构

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

原stg_customers.sql代码(错误版本)

with customers as (

    select
        id as customer_id,
        first_name,
        last_name

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

)

select * from customers 

内容的提问来源于stack exchange,提问作者Jérémie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 06:15:43