-
Notifications
You must be signed in to change notification settings - Fork 6
Version 0.10.0 breaks dbt compile #74
Copy link
Copy link
Open
Description
Bug: dbt compile crashes when prefer_recent is enabled
Environment
| Component | Version |
|---|---|
upstream_prod |
0.10.0 |
dbt-core |
1.11.6 |
dbt-snowflake |
1.11.2 |
| Python | 3.10.18 |
| OS | Linux |
Steps to reproduce
- Set
upstream_prod_prefer_recent: trueindbt_project.yml - Run
dbt compile -s <any_model>
Error
Runtime Error
Compilation Error in model <model> (models/marts/<folder>/<model>.sql)
'dict object' has no attribute '_upstream_prod_cache'
> in macro ref (macros/ref.sql)
> called by macro ref (macros/ref.sql)
> called by model <model> (models/marts/<folder>/<model>.sql)
Root cause
populate_cache() runs via on-run-start, which doesn't execute during dbt compile. However, dbt compile sets execute = true, so default__ref enters the prefer_recent branch and accesses graph["_upstream_prod_cache"] with bracket notation — which fails because the key was never set.
The execute is false guard at the top of default__ref does not protect against this because execute is true during compile (it's only false during parse).
Affected commands
dbt compile- Likely
dbt showand any command that compiles without running hooks
Unaffected commands
dbt run,dbt build,dbt test(all execute hooks)
Suggested fix
Either guard the cache access in default__ref:
{% if prefer_recent is true and dev_exists is true and "_upstream_prod_cache" in graph %}Or ensure populate_cache always sets the key (even as an empty dict) and use .get() for the inner lookup.
Workaround
In a custom ref.sql wrapper, disable prefer_recent when the cache is absent:
{% if prefer_recent and "_upstream_prod_cache" not in graph %}
{% set prefer_recent = false %}
{% endif %}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels