Skip to content

Version 0.10.0 breaks dbt compile #74

@colombian-cannonball

Description

@colombian-cannonball

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

  1. Set upstream_prod_prefer_recent: true in dbt_project.yml
  2. 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 show and 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 %}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions