Skip to content

Commit

Permalink
clarify builtin macros aren't overridden via package
Browse files Browse the repository at this point in the history
  • Loading branch information
mirnawong1 committed Jul 17, 2024
1 parent b742af5 commit e0b286a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions website/docs/reference/dbt-jinja-functions/builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ From dbt v1.5 and higher, use the following macro to override the `ref` method a

It includes logic to extract user-provided arguments, including <code>version</code>, and call the <code>builtins.ref()</code> function with either a single <code>modelname</code> argument or both <code>packagename</code> and <code>modelname</code> arguments, based on the number of positional arguments in <code>varargs</code>.

Note that the `ref`, `source`, and `config` functions can't be overridden with a package. This is because `ref`, `source`, and `config` are context properties within dbt and are not dispatched as global macros. Refer to [this GitHub discussion](https://github.com/dbt-labs/dbt-core/issues/4491#issuecomment-994709916) for more context.

<br /><br />


Expand Down
4 changes: 4 additions & 0 deletions website/docs/reference/dbt-jinja-functions/dispatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ As a package maintainer, this functionality enables users of my package to exten

### Overriding global macros

:::tip
Certain functions like [`ref`](/reference/dbt-jinja-functions/ref), [`source`](/reference/dbt-jinja-functions/source), and [`config`](/reference/dbt-jinja-functions/config) can't be overridden with a package using the dispatch config. This is because `ref`, `source`, and `config` are context properties within dbt and are not dispatched as global macros. Refer to [this GitHub discussion](https://github.com/dbt-labs/dbt-core/issues/4491#issuecomment-994709916) for more context.
:::

I maintain an internal utility package at my organization, named `my_org_dbt_helpers`. I use this package to reimplement built-in dbt macros on behalf of all my dbt-using colleagues, who work across a number of dbt projects.

My package can define custom versions of any dispatched global macro I choose, from `generate_schema_name` to `test_unique`. I can define a new default version of that macro (e.g. `default__generate_schema_name`), or custom versions for specific <Term id="data-warehouse" /> adapters (e.g. `spark__generate_schema_name`).
Expand Down

0 comments on commit e0b286a

Please sign in to comment.