sqlfluff: Undefined jinja template variable: 'dbt_utils'

62 views Asked by At

Running pre-commit with sqlfluff returns the error: enter image description here

Sqlfluff is in the root folder along with pre-commit-config.yaml. I have tried moving it to /dbt but the error persists.

I have tried changing templater = jinja to templater = dbt and it said: enter image description here

But after pip installing sqlfluff-templater-dbt, restarting the terminal and VS code, the same error remains.

Here is how I am using dbt_utils:

select
{{ dbt_utils.generate_surrogate_key([
        'date',          
        'start',
        'end'
    ])
}} as hash
from {{ source('bronze', 'test') }}

This is my sqlfluff:

[sqlfluff]
dialect = databricks
templater = jinja
exclude_rules = structure.column_order

[sqlfluff:templater:jinja]
apply_dbt_builtins = true

[sqlfluff:templater:jinja:macros]
# Macros provided as builtins for dbt projects
dbt_ref = {% macro ref(model_ref) %}{{model_ref}}{% endmacro %}
dbt_source = {% macro source(source_name, table) %}{{source_name}}_{{table}}{% endmacro %}
dbt_config = {% macro config() %}{% for k in kwargs %}{% endfor %}{% endmacro %}
dbt_var = {% macro var(variable, default='') %}item{% endmacro %}
dbt_is_incremental = {% macro is_incremental() %}True{% endmacro %}

I have dbt/dependencies.yml as (and ran dbt deps prior):

packages:
  - package: dbt-labs/dbt_utils
    version: 1.1.1

Also, everything worked fine prior to my usage of dbt_utils so it's something to do with it. Appreciate the help!

0

There are 0 answers