Skip to content

Fix: Only keep refs and sources that exist to match dbt load time behaviour#5509

Merged
themisvaltinos merged 3 commits intomainfrom
themis/missingref
Oct 8, 2025
Merged

Fix: Only keep refs and sources that exist to match dbt load time behaviour#5509
themisvaltinos merged 3 commits intomainfrom
themis/missingref

Conversation

@themisvaltinos
Copy link
Contributor

During parsing sqlmesh captures all refs/sources including those that might be in {% if false %} blocks. For example the below model would lead at load time error in sqlmesh by failing on the missing reference:

{{ config(
    materialized='table',
) }}

{% if true %}
    WITH source AS (
        SELECT *
        FROM {{ ref('simple_model_a') }}
    )
{% else %}
    WITH source AS (
        SELECT *
        FROM {{ ref('nonexistent_model') }} -- this doesn't exist but is in unexecuted branch
    )
{% endif %}
SELECT * FROM source

Dbt on the other hand happily proceeds at load time and then since the branch is never exercised runs the model successfully. If there was an actual missing reference it would fail at runtime. So this aims to match this behaviour by intersecting static analysis results with dbt's manifest refs and sources so that we not raise at load time.

@themisvaltinos themisvaltinos requested a review from a team October 8, 2025 14:48
@themisvaltinos themisvaltinos merged commit c8bee08 into main Oct 8, 2025
35 of 36 checks passed
@themisvaltinos themisvaltinos deleted the themis/missingref branch October 8, 2025 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants