Skip to content

Commit

Permalink
clarify builtin macros aren't overridden via package (#5792)
Browse files Browse the repository at this point in the history
this pr clarifies that builtin macros can't be overridden because they
aren't deferred and are context properties defined in python.

Resolves #971
  • Loading branch information
mirnawong1 authored Jul 18, 2024
1 parent 331ad88 commit 6ba5fda
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion website/docs/reference/dbt-jinja-functions/builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ 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>.

<br /><br />
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 />


```
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 6ba5fda

Please sign in to comment.