Skip to content

Fix ref macro override to support package args and version keyword - #316

Open
haritamar wants to merge 1 commit into
dremio:mainfrom
haritamar:fix/232-ref-macro-package-version-support
Open

Fix ref macro override to support package args and version keyword#316
haritamar wants to merge 1 commit into
dremio:mainfrom
haritamar:fix/232-ref-macro-package-version-support

Conversation

@haritamar

Copy link
Copy Markdown

Summary

Fix the ref macro override in builtins.sql to correctly support all dbt ref() calling conventions.

Description

The current override has the signature ref(model_name, v=None), which breaks two valid dbt calling conventions:

  1. Two-positional-arg formref('package', 'model') for cross-package/project refs: the second positional arg was incorrectly interpreted as a version number instead of a model name.
  2. version keyword argumentref('model', version=1) was not accepted at all (only v= was supported).

The fix adopts the correct interface per the dbt docs on builtins overrides:

-{%- macro ref(model_name, v=None) -%}
-  {%- set relation = builtins.ref(model_name, v=v) -%}
-  {%- if execute and graph -%}
-    {%- set model = graph.nodes.values() | selectattr("name", "equalto", model_name) | list | first -%}
+{%- macro ref(model_name_or_package, model_name=none, v=none, version=none) -%}
+  {%- set effective_version = v if v is not none else version -%}
+  {%- if model_name is not none -%}
+    {%- set relation = builtins.ref(model_name_or_package, model_name, v=effective_version) -%}
+    {%- set _model_name = model_name -%}
+  {%- else -%}
+    {%- set relation = builtins.ref(model_name_or_package, v=effective_version) -%}
+    {%- set _model_name = model_name_or_package -%}
+  {%- endif -%}
+  {%- if execute and graph -%}
+    {%- set model = graph.nodes.values() | selectattr("name", "equalto", _model_name) | list | first -%}

Note: the same bug was independently identified and worked around in elementary-data/elementary, which added a local ref override specifically to compensate for this dbt-dremio issue.

Test Results

Manually verified the macro logic against all calling forms:

  • ref('model') — unchanged behaviour
  • ref('package', 'model') — now works correctly
  • ref('model', v=1) — unchanged behaviour
  • ref('model', version=1) — now works correctly

Changelog

  • Added a summary of what this PR accomplishes to CHANGELOG.md

Contributor License Agreement

Related Issue

Fixes #232

The overridden ref macro only accepted (model_name, v=None), which
broke two valid dbt calling conventions:
- ref('package', 'model') - cross-package/project refs
- ref('model', version=1) - versioned models via the `version` kwarg

Updated the signature to match the correct interface per the dbt docs
on builtins overrides, mirroring the same fix applied in elementary-data/elementary#404708b.

Fixes dremio#232

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Mar 3, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Override of ref macro does not support packages or the "version" keyword argument

2 participants