Skip to content

Commit 404708b

Browse files
fix: add ref() macro override for dbt-core 1.11 compatibility (#2137)
* fix: add ref() macro override for dbt-core 1.11 compatibility Some adapters (e.g. dbt-dremio) override the ref() Jinja macro with a signature that doesn't support the two-argument positional form used for cross-package references: ref('package', 'model'). dbt-dremio's ref(model_name, v=None) intercepts the second positional arg as a version identifier, breaking refs like ref('elementary', 'dbt_models'). This override in the elementary_cli monitor project forwards all arguments directly to builtins.ref(), which correctly handles all ref() forms in dbt-core 1.11+. It also supports the legacy package= keyword form for backward compatibility. Co-Authored-By: Itamar Hartstein <haritamar@gmail.com> * fix: handle combined cross-package + versioned refs for forward compatibility Co-Authored-By: Itamar Hartstein <haritamar@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Itamar Hartstein <haritamar@gmail.com>
1 parent 746ce41 commit 404708b

File tree

1 file changed

+40
-0
lines changed
  • elementary/monitor/dbt_project/macros/overrides

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{#
2+
Override adapter-specific ref() macros (e.g. dbt-dremio) that don't properly
3+
handle the two-argument positional form: ref('package', 'model').
4+
5+
dbt-dremio's ref(model_name, v=None) intercepts the second positional arg as
6+
a version identifier, breaking cross-package refs like ref('elementary', 'dbt_models').
7+
8+
This override forwards all arguments directly to builtins.ref(), which correctly
9+
handles all ref() forms in dbt-core 1.11+:
10+
- ref('model') -> single model lookup
11+
- ref('package', 'model') -> cross-package ref
12+
- ref('model', v=1) -> versioned ref
13+
- ref('model', version=1) -> versioned ref (alias)
14+
- ref('model', package='package') -> cross-package ref (legacy keyword form)
15+
#}
16+
17+
{%- macro ref(model_name_or_package, model_name=none, v=none, version=none, package=none) -%}
18+
{%- set effective_version = v if v is not none else version -%}
19+
{%- if model_name is not none -%}
20+
{#- Two-arg positional: ref('package', 'model') -#}
21+
{%- if effective_version is not none -%}
22+
{%- do return(builtins.ref(model_name_or_package, model_name, v=effective_version)) -%}
23+
{%- else -%}
24+
{%- do return(builtins.ref(model_name_or_package, model_name)) -%}
25+
{%- endif -%}
26+
{%- elif package is not none -%}
27+
{#- Legacy keyword: ref('model', package='pkg') -#}
28+
{%- if effective_version is not none -%}
29+
{%- do return(builtins.ref(package, model_name_or_package, v=effective_version)) -%}
30+
{%- else -%}
31+
{%- do return(builtins.ref(package, model_name_or_package)) -%}
32+
{%- endif -%}
33+
{%- elif effective_version is not none -%}
34+
{#- Versioned: ref('model', v=1) or ref('model', version=1) -#}
35+
{%- do return(builtins.ref(model_name_or_package, v=effective_version)) -%}
36+
{%- else -%}
37+
{#- Simple: ref('model') -#}
38+
{%- do return(builtins.ref(model_name_or_package)) -%}
39+
{%- endif -%}
40+
{%- endmacro -%}

0 commit comments

Comments
 (0)