-
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-746] [Bug] Variables not getting into packages #5368
Comments
Is this issue related? #2769 |
I tried another approach, having package-scoped variables, but passing the value with a new variable: Parent project: vars:
my_var: "{{var('MY_VAR')}}"
base_package:
parent_my_var: "{{var('MY_VAR')}}" In vars:
my_var: "{{var('parent_my_var')}}" But this just results a similar error:
|
I'm not sure what the reason for this is, but the code explicitly says that cli vars won't be passed to the project creation for dependencies. In the 'new_project' method of RuntimeConfig, in core/dbt/config/runtime.py:
|
It would be possible to pass in the cli_vars to dependency project creation, since 'load_dependencies' is called from RuntimeConfig (which should already have the cli_vars). |
Ah, I think what's actually happening here is that # dbt_project.yml
vars:
my_var: "{{ 'val_one' if target.name == 'prod' else 'val_two' }}" But it won't actually be rendered when
One other thing: If you install other projects as packages, it is still always expected that you're executing dbt from the top-level / root project. (That's definitionally true: The root project is always the one from/in which you are invoking dbt.) The |
So... If I want to pass a variable to It sounds like I might need to have some pre-dbt shell script that modifies |
I was invoking dbt from the directory of |
The solution I ended up using: Remove the variables from |
I'm having a similar issue here where i'm defining a conditional var value for a database name in my dbt_project.yml that i'm using in my sources yaml but when I attempt to use a source using the |
just ran into an issue that sounds related, but it could maybe be specific to using variables to dynamically enable sources from the src.yml file basically, in our Hubspot Source package, we have some variables to disable models associated with the Hubspot Service endpoint (and many other tables, but i'll just refer to service ones for this example). In the package's dbt_project.yml file, we set the However, the source similar to @solomonshorser, we had to remove the variable from the package's dbt_project.yml, which is a little bit of a bummer as it's nice to have all of the default values for the variables easily accessible in one place (rather than in-line) but perhaps that's better suited for the README. I remember @jtcohen6 saying you shouldn't add variable values to a package dbt_project.yml, but this seems kinda funky |
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 comment on the issue or else it will be closed in 7 days. |
Is any further work happening on this? |
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 comment on the issue or else it will be closed in 7 days. |
Is there an existing issue for this?
Current Behavior
I have a project that relies on a base package. Some of the values in that base package's dbt_project file should come from the parent project. Values for variables are passed to the parent package from the CLI, via the
--vars...
option. The base project does not seem to get the value.In the parent dbt_project file:
In the base project:
When executing commands the use
my_var
in the base project, I get errors of the form:MY_VAR
in this case is used to dynamically determine a BigQuery project ID, but in this case, you can see that the literal'{{ var('MY_VAR') }}'
was used instead of the value.I also tried specifying the project in the parent's vars block, but it did not seem to work:
This happens when I run
dbt test
.dbt compile
does not have any problems.Expected Behavior
My expectation is that the value from the CLI
... --vars '{ "MY_VAR": "some-value", ... } '
would be used in both the parent project and the base project.This is based on the wording here: https://docs.getdbt.com/docs/building-a-dbt-project/building-models/using-variables
And also
(emphasis mine)
Did I misunderstand the documentation?
IS there a way to pass a variables value from the CLI to the packages that a project depends on?
Steps To Reproduce
MY_VAR
but base project cannot.Relevant log output
No response
Environment
What database are you using dbt with?
bigquery
Additional Context
No response
The text was updated successfully, but these errors were encountered: