DBT测试检测到失败行但Snowflake失败表为空求助
DBT测试检测到失败行但Snowflake失败表为空的问题
我的DBT测试检测到约1250条失败行,但Snowflake中对应的失败表test_unit4_missing_time始终为空:
- DBT每日06:00的管道运行成功,手动执行
dbt test -s test_unit4_missing_time --store-failures也能检测到失败 - 已配置
store_failures=True且DBT能写入正确schema,但运行时未重新创建表 - 最初是临时表,改成永久表(
CREATE OR REPLACE TABLE)后,表的last_altered时间戳会更新,但仍无数据
已完成的排查操作:
- 执行
dbt test -s test_unit4_missing_time --store-failures --debug,未观测到INSERT INTO dbt_dev.test_unit4_missing_time语句 - 更新
dbt_project.yml配置:
无任何变化tests: +store_failures: true +on_schema_change: append_new_columns - 执行
SHOW GRANTS ON TABLE dbt_dev.test_unit4_missing_time;,确认DBT用户拥有INSERT、UPDATE、DELETE权限 - 执行以下SQL确认失败表位置:
确认表位于预期的SELECT table_schema, table_name, last_altered FROM information_schema.tables WHERE table_name LIKE 'dbt_test__%';dbt_devschema中 - 禁用Snowflake查询缓存后查询:
表仍无数据ALTER SESSION SET USE_CACHED_RESULT = FALSE; SELECT * FROM dbt_dev.test_unit4_missing_time; - 删除表后重新运行测试:
执行DROP TABLE dbt_dev.test_unit4_missing_time;dbt test -s test_unit4_missing_time --store-failures,DBT未创建新表但仍报告1250条失败行
可能的原因及解决方法
1. 测试类型不支持store_failures
仅数据测试(data tests)(包括内置测试如not_null/unique、自定义SQL测试)支持存储失败行,且自定义测试的SQL必须返回失败记录集,而非布尔断言。
- 检查测试SQL:确保是返回失败行的查询,比如:
而非仅返回计数的断言:select * from {{ ref('target_table') }} where time_column is nullselect count(*) from {{ ref('target_table') }} where time_column is null having count(*) > 0
2. 配置优先级冲突
DBT配置优先级为:命令行参数 > 测试级别配置 > 模型级别配置 > 项目级别配置
- 检查
schema.yml中该测试的局部配置,是否覆盖了store_failures: false:models: - name: target_table tests: - test_unit4_missing_time: store_failures: false # 此配置会覆盖全局设置
3. 失败表命名/类型不匹配
DBT默认生成的失败表命名为dbt_test__<test_identifier>,手动修改表类型(临时改永久)可能导致DBT无法匹配目标表:
- 查看debug日志中
Creating failure table或Inserting failures into关键字,确认DBT实际操作的表名 - 不要手动修改表类型,通过配置指定永久表:
之后删除手动创建的表,让DBT自动生成。tests: - test_unit4_missing_time: store_failures: true +materialized: table # 指定为永久表,替代默认临时表
4. Snowflake事务/查询历史排查
- 查看Snowflake查询历史,搜索DBT运行时段的相关语句,确认是否有
INSERT语句被回滚或报错 - 检查DBT用户的事务设置,确保
AUTOCOMMIT为开启状态(默认开启)
5. DBT版本兼容性
旧版本DBT(<1.0)在Snowflake的store_failures功能存在已知bug:
- 执行
dbt --version检查版本,升级至最新稳定版(如1.6+)后重试
6. 验证测试SQL的实际返回结果
- 从
target/compiled目录中找到该测试的编译后SQL,直接在Snowflake中执行,确认是否真的返回1250条失败记录
内容的提问来源于stack exchange,提问作者Aagaard
相关产品推荐
相关产品推荐

