-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[CT-3505] [Bug] Unable to access global variables like schemas and database_schemas in dbt_project.yml on-run-end #9301
Comments
Thanks for reaching out @gclarkjr5 ! It looks like you are using the Can you share more about your use-case why you're hoping to see these listed in If you run Here's a minimal example:
|
@dbeatty10 If you @gclarkjr5 I notice you don't expect I also notice that |
Thanks for your insights @alison985 💡 |
@gclarkjr5 I can see how it would be nice to be able to do a "dry run" using dbt compile and then see the logic that dbt will use. But in this case, the reason that So in the case of Accordingly, I'm going to close this as "not planned" since those context variables are behaving in the way they are documented. |
So if anyone is interested in how I was able to fix this, here was what I was finally able to uncover. In the setup we have, Airflow is what orchestrates DBT. The people from Astronomer have some python code that parses a DBT manifest file, and then re-creates the dependency chain in Airflow as a DAG so that your models still run in their correct order. You can find the Astronomer article & code here. Each model therefore is its own "run". And since each model is its own "run" it will run the {% macro grant_usage_to_schemas(schemas, user) %}
{% if flags.WHICH == "run" %}
{% for schema in schemas %}
grant usage on schema {{ schema }} to {{ user }};
{% endfor %}
{% else %}
select 1;
{% endif %}
{% endmacro %} DBT allows you to create conditional logic around the flags or commands passed to it. In this case, if its a "run", run the grant, else perform a |
@dbeatty10 I'm noticing that |
@ataft I didn't check the code to confirm for certain, but my belief is that it's related to my comment above. i.e., if a |
Is this a new bug in dbt-core?
Current Behavior
I am currently trying to grant usage for a user to all schemas. I have used the examples provided and have the following:
my macro grants.sql
my dbt_project.yml
while the 2nd on-run-end hook produces what i need, I would have expected the first one to do the same thing. But instead i get an empty output after running dbt compile
/target/compiled/warehouse/dbt_project.yml/hooks/warehouse-on-run-end-0.sql
-- noqa: LT02
Expected Behavior
after running dbt compile, I would have expected to see the compiled SQL of my on-run-end hooks. Instead, the one where i explicitly use the schemas object shows nothing, like in the above code block. However, I would have expected the following.
/target/compiled/warehouse/dbt_project.yml/hooks/warehouse-on-run-end-0.sql
/target/compiled/warehouse/dbt_project.yml/hooks/warehouse-on-run-end-1.sql
Steps To Reproduce
My full dbt_project.yml
Create a test model for each schema. Then run dbt compile.
Relevant log output
No response
Environment
Which database adapter are you using with dbt?
postgres
Additional Context
I can attach the logs if there is no quick solution/the issue is immediately apparent to someone.
The text was updated successfully, but these errors were encountered: