Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse model hooks for ref statements #1957

Closed
drewbanin opened this issue Nov 25, 2019 · 1 comment
Closed

Parse model hooks for ref statements #1957

drewbanin opened this issue Nov 25, 2019 · 1 comment
Labels
bug Something isn't working

Comments

@drewbanin
Copy link
Contributor

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:

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).

@drewbanin drewbanin added the bug Something isn't working label Nov 25, 2019
@drewbanin drewbanin added this to the 0.15.2: Barbara Gittings milestone Nov 25, 2019
beckjake added a commit that referenced this issue Jan 6, 2020
@drewbanin
Copy link
Contributor Author

closed by #2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant