You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hooks are not currently "parsed" at parse-time - they are just executed directly at runtime. As a result, a ref in a hook can result in an error message like:
dbt was unable to infer all dependencies for the model "table_a".
This typically happens when ref() is placed within a conditional block.
To fix this, add the following hint to the top of the model "table_a":
-- depends_on: {{ ref('table_b') }}
This error can be avoided by parsing model hooks at parse-time.
Steps To Reproduce
-- models/model_a.sql
select 1 as id
-- models/model_b.sql
{{ config(post_hook="select * from {{ ref('model_a') }}") }}
select 1 as id
run the models shown above and observe the error message.
Beware
Parsing hooks should be straightforward and a non-issue most of the time, but some users might be (read: are definitely) doing weird things in hooks. All of the adapter methods that invoke SQL queries should be no-op'd at parse-time.... are there valid hooks that would fail if dbt starts parsing them?
Example hook that's no problem to parse
grant select on {{ this }} to db_reader
Example hook that may be problematic (contrived)
{% for node in graph.nodes.values() %}
-- this wouldn't work anyway - just an example
grant select on schema.{{ node.identifier }}
{% endfor %}
We should better codify the hook context available at parse-time and run-time and document what kinds of hook queries, if any, are no longer supported (or how to work around this change).
The text was updated successfully, but these errors were encountered:
Describe the bug
Hooks are not currently "parsed" at parse-time - they are just executed directly at runtime. As a result, a
ref
in a hook can result in an error message like:This error can be avoided by parsing model hooks at parse-time.
Steps To Reproduce
run the models shown above and observe the error message.
Beware
Parsing hooks should be straightforward and a non-issue most of the time, but some users might be (read: are definitely) doing weird things in hooks. All of the adapter methods that invoke SQL queries should be no-op'd at parse-time.... are there valid hooks that would fail if dbt starts parsing them?
Example hook that's no problem to parse
Example hook that may be problematic (contrived)
We should better codify the hook context available at parse-time and run-time and document what kinds of hook queries, if any, are no longer supported (or how to work around this change).
The text was updated successfully, but these errors were encountered: