-
Notifications
You must be signed in to change notification settings - Fork 97
Description
dbt Fusion dbt1000 Warning: {{ this }} in Post-Hook
Overview
This example is a minimal reproducible example demonstrating a dbt1000 diagnostic triggered by the dbt Fusion VSCode extension when {{ this }} is used inside a +post-hook defined at the project level in dbt_project.yml. The desired behavior is that post-hooks do not trigger this warning.
Environment
| Component | Version |
|---|---|
| dbt Fusion VSCode Extension | v0.48.0 |
| dbt-fusion | 2.0.0-preview.120 |
Warning
The dbt Fusion language server emits the following diagnostic:
warning: dbt1000: Detected unsafe introspection which may lead to non-deterministic
static analysis. To suppress this warning, set static_analysis to 'unsafe' in the
nodes' configuration. Learn more: https://docs.getdbt.com/docs/fusion/new-concepts.
Nodes: 'model.posthook.junk_model' (this)
Trigger
The warning is produced by the project-level +post-hook in dbt_project.yml, which applies to every model in the project:
models:
+post-hook:
- "GRANT SELECT ON {{ this }} TO analyst_role"{{ this }} refers to the fully-qualified relation name of the model being materialized (e.g. posthook.main.junk_model). It is valid dbt syntax at runtime and resolves correctly during dbt run, but the dbt Fusion language server cannot resolve it statically at parse/lint time — hence the dbt1000 warning.
Project Configuration
dbt_project.yml
name: 'posthook'
version: '1.0.0'
config-version: 2
profile: 'posthook'
model-paths: ["models"]
models:
+post-hook:
- "GRANT SELECT ON {{ this }} TO analyst_role"profiles.yml
posthook:
target: dev
outputs:
dev:
type: duckdb
path: posthook.duckdb
threads: 1models/junk_model.sql
{{ config(
materialized='table'
) }}
select
1 as id,
'foo' as name,
42 as valueWhy This Happens
dbt Fusion performs static analysis on model files without executing them. {{ this }} is an introspective reference that only has meaning during materialization — it points to the relation that is currently being built. Since the LSP has no runtime context, it flags {{ this }} as unsafe for static analysis.
The Workaround Problem
The diagnostic message suggests suppressing the warning by setting static_analysis to unsafe. However, because the +post-hook is defined at the project level, the only way to suppress it is to opt every model in the project out of safe static analysis:
models:
+post-hook:
- "GRANT SELECT ON {{ this }} TO analyst_role"
+static_analysis: unsafeThis is a blunt instrument — it disables safe static analysis across the entire project rather than for the specific context where {{ this }} is legitimately used. There is no way to scope static_analysis: unsafe to just the post-hook expression itself.
Alternative: grants Config
For the specific use case of granting SELECT on a model, dbt provides a first-class grants config that avoids post-hooks entirely:
models:
+grants:
select: ["analyst_role"]This is declarative, does not use {{ this }}, and will not trigger the dbt1000 warning. It is the preferred approach for permission management on supported adapters (Snowflake, Postgres, Redshift, BigQuery, Databricks, and others).
When You Still Need {{ this }} in a Post-Hook
The grants config only covers simple privilege grants. There are legitimate use cases where {{ this }} in a post-hook is the only option, for example:
- Running adapter-specific DDL after materialization (e.g.
ALTER TABLE {{ this }} CLUSTER BY (...)) - Calling a stored procedure that takes the relation name as an argument
- Logging or auditing queries that reference the materialized relation
- Any post-processing that requires the fully-qualified table name
In these cases the dbt1000 warning is a false positive, and the only current option is to accept static_analysis: unsafe at whatever scope the hook is applied.
Is this a discrepancy between the dbt Fusion Engine and dbt Core? Check one.
- YES
- NO
Operating System and CPU Type (please complete the following information):
- Mac