-
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
run_query works in run-operation mode but doesn't seem to work during dbt_project.yaml querying #1760
Comments
Hey @whisperstream - this won't work for two reasons:
The first item here is subject to change, but the second one probably is not. Can you tell me more about why you're storing the results of this query in a dbt variable? Is it to cache the results so they can be used across multiple different models? If so, there might be alternative ways to accomplish this that we can explore! |
Yes, am trying to cache the results, again all this goes back to solving for having different roles access different parts of the dbt model. In order to rewrite the models correctly (as discussed here: #1695 (comment)) I'm trying to figure out which roles the user has. (because I need to know in my |
Any other alternatives are greatly welcomed :) |
Ok - thanks for that context! It's hard for me to remember which issues are correlated - I appreciate you referencing #1695 here! I think that it would be totally reasonable for something like this to work in dbt:
Unfortunately, there's a whole lot of bootstrapping that dbt needs to do at startup, and at the point where the A much more direct path to supporting this type of use case would be to provide an arbitrary key/value cache in the dbt context. I think we'd just need to expose a dictionary context variable, called
So, the first time you call There are other ways to implement something like this too -- the Both of these are interesting ideas, but there's one very big problem: they don't play well with parallelism. If you run 8 dbt models at in parallel, all of which call the So, this is all to say: the thing you want to do is reasonable, but we don't have a great answer for how to address it in dbt today. In general, the problem is that the state that dbt needs to operate on lives in your database, and not inside of a dbt resource. This is definitely reasonable (and almost necessary) for permissions, but it's not really a pattern that we've designed for explicitly. Curious to hear what you think about all this! Edit: maybe there's a way to cache the results in the |
I am trying to create a database clone before all models start. Models are supposed to use that clone as a target. I can not achieve this with "on-run-start" for the reason explained above. I am trying to do blue-green flow, where a clone is temporally created as stage database. (snowflake) |
This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please remove the stale label or comment on the issue, or it will be closed in 7 days. |
Although we are closing this issue as stale, it's not gone forever. Issues can be reopened if there is renewed community interest; add a comment to notify the maintainers. |
Describe the bug
I have a case where I'm trying to get the users roles from the database when dbt runs (in either compile/run mode). I have a macro called
get_user_roles
and have added the following to my dbt_project.ymlWhen I execute
dbt run
ordbt compile
, dbt does connect to the database but it does not return any results from therun_query
command in my macro. If I run the same macro inrun-operation
mode it works just fine.Was trying to see if there was any documentation to say when run_query works or doesn't work but was unable to find it.
Steps To Reproduce
The value of MY_VAR should be the result of the query but instead it's None
Expected behavior
Expected dbt to connect to the database and execute the query
Screenshots and log output
If applicable, add screenshots or log output to help explain your problem.
System information
Which database are you using dbt with?
The output of
dbt --version
:The operating system you're using:
OSX
The output of
python --version
:Python 3.7.3
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: