-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
get_relation returns none in hook context #2938
Comments
@jtcohen6 - Thanks for raising this in our slack thread. I'm seeing the same from It seems this must have been working at some point - is it possible this is a recent regression, and would it be worthwhile for me to try this in a previous version of DBT? |
@jtcohen6 - Do you know if the |
@aaronsteers Hm... I haven't looked into this, but I'd be curious to know if it works in older versions!
During a model's execution, |
@jtcohen6 - This is super helpful - thank you! The expression Do you know if I can use the model object also to get the fully qualified object name that I would otherwise get from OR (asked another way) can I get a |
It's possible to do something like this (docs):
Effectively, it's the same as |
Thanks for sharing this - and for the link. I had checked that page but it doesn't say anything directly about the This might be unrelated, but is there a known reason why I wouldn't be able to access a macro attached to a specific model from a In Sample that throws the error: version: 2
models:
- name: dim_work_group
+post-hook:
- "{{ grant_select(this, 'PEOPLEDATA_RO') }}" |
Right, that docs link details how to instantiate As far as setting The specific error you're seeing is the result of another limitation that, in an ideal world, I'd like to make possible: You cannot call custom macros from |
That is super helpful context and I think it gives me my path forward. Thanks so much! |
Coming back to this, and having revisited #2370, I'm afraid to report that this does work if the hook is re-parsed at execute time, instead of set at parse time. Namely:
This is so not my favorite thing, but I'm going to close the issue. The real question is bigger than |
Describe the bug
The
adapter.get_relation(...)
method seems to returnNone
within the post-hook context.Why does this matter? Well,
{{ this }}
always has itstype
defined asNone
, and it's fairly common that a user would want to useget_relation
(perform a cache lookup) to get its relational type for the purposes of templating a post hook:Steps To Reproduce
macros/say_hi.sql
models/my_model.sql
{{ config( post_hook = say_hi(this) ) }} {{ say_hi(this) }}
dbt.log
Expected behavior
I expected the result of
get_relation
to be defined for both the model and post-hook contexts.The output of
dbt --version
:Additional context
In the meantime, it's mostly possible to work around this by inferring the relational object type from the configuration of the model we're post-hooking:
The text was updated successfully, but these errors were encountered: