Skip to content

Commit fdcb302

Browse files
fix: gate deferral fallback on --defer/--favor-state flags
Only construct a synthetic Relation when dbt deferral is actually active (invocation_args_dict.defer or favor_state). Without this guard, the fallback would fire for any installed Elementary model whose table doesn't exist yet (e.g. partial dbt run), breaking callers that rely on a None return to detect missing tables. Co-Authored-By: Noy Arie <noyarie1992@gmail.com>
1 parent cb00d62 commit fdcb302

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

macros/utils/graph/get_elementary_relation.sql

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,21 @@
2424
elementary_database, elementary_schema, identifier_alias
2525
) %}
2626
{% if relation is not none %} {% do return(relation) %} {% endif %}
27-
{# Relation not found in the target schema. This can happen when
28-
dbt deferral (--favor-state / --defer) is active and the
29-
Elementary models exist in the deferred (e.g. prod) schema
30-
but were not built in the current target. Construct a relation
31-
from the graph node coordinates so the generated SQL references
32-
the correct schema instead of rendering "from None". #}
33-
{% if identifier_node %}
27+
{# Relation not found in the target schema. Under dbt deferral
28+
(--favor-state / --defer) the Elementary models may exist only
29+
in the deferred (e.g. prod) schema and not in the current
30+
target. Construct a relation from the graph node coordinates
31+
so the generated SQL references the correct schema instead of
32+
rendering "from None". #}
33+
{% set is_defer = (
34+
(
35+
invocation_args_dict.get("defer", false)
36+
or invocation_args_dict.get("favor_state", false)
37+
)
38+
if invocation_args_dict
39+
else false
40+
) %}
41+
{% if identifier_node and is_defer %}
3442
{% do return(
3543
api.Relation.create(
3644
database=elementary_database,

0 commit comments

Comments
 (0)