-
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-1888] [Bug] Package project yml configs overriding root project configs when used in other yml files #6705
Comments
Thanks for (re)opening this @rlh1994! I was able to reproduce the precedence for variable declaration you described (package vars preceding project vars) with an example pared down to a model (not tests) by:
version: 2
models:
- name: model_a
config:
enabled: '{{ var("enabled_test", true) }}'
❯ dbt compile
15:16:00 Running with dbt=1.3.0
15:16:00 Unable to do partial parsing because a project config has changed
15:16:01 Found 0 models, 0 tests, 0 snapshots, 0 analyses, 500 macros, 0 operations, 3 seed files, 0 sources, 0 exposures, 0 metrics
15:16:01
15:16:02 Concurrency: 4 threads (target='dev')
15:16:02
15:16:02 Done. From our documentation on variable precedence:
Unfortunately our docs aren't clear on which dbt_project.yml gets used, the one from the package or the one in the root project. In this case, the package dbt_project.yml always takes precedence regardless of whether global or package-scoped vars are defined in the root dbt_project.yml. As you've outlined, the vars in root-level dbt_project.yml should actually take precedence over the vars in package-level dbt_project.yml. This is what happens in other cases and is generally expected given how the configuration hierarchy works (= root-level dbt_project.yml config "wins," even over more-specific configurations defined in packages). All that said, I’m curious to hear more about your use case! Is the idea to set vars from an encompassing project to configure the behaviour of an installed package? Given that |
Glad you were able to reproduce! Sure, our main use case is around enabling/altering tests based on variables (as pretty much all our other varaibles are used directly in models/macros so don't hit this issue). Because we support multi-warehouses but have a different data structure for redshift/postgres we can end up with tests defined on models that aren't enabled, which raises a warning for our users and clogs the logs. We also have one case where a table may be unique across 2 columns instead of one depending on a variable so again that's impacted by a variable: Our main approach to variables more generally is:
|
Gotcha! If I could summarize the desired/expected behaviour with regards to variables precedence, it would be (highest precedence first):
4 and 5 seem swappable for the scenarios to resolve the scenarios outlined. Given the workarounds available and likely complexity of this change, this will probably remain a lower priority issue but should definitely be taken into account for any vars refactoring work done in dbt-core. |
Is this a new bug in dbt-core?
Current Behavior
When a variable is used within a yaml file within a package (such as one containing model tests), this variable is taking precidence from the package config, not the project config as expected.
It is possible to workaround this currently by not setting the default in the yaml and setting it in each var call, but this is not ideal and it hides variables throughout the code and makes mistakes with changes more likely.
Expected Behavior
The variable would always take precidence from the project, allowing defaults to be set in the package yaml, but could be overwritten in the project yaml.
Steps To Reproduce
enabled_test
(give it the valuetrue
), and a yaml file for that model with some test.enabled:
condition of that test to bevar('enabled_test')
dbt compile
- you should see 1 testenabled_test
to false in your main project yaml, rundbt compile
you should still see 1 testenabled_test
to true in your main project yaml, and false in your package (dbt deps
if not locally installed), rundbt compile
you should see 0 tests.Relevant log output
No response
Environment
Which database adapter are you using with dbt?
No response
Additional Context
Reopen of: #3698 but with non-source freshness specific scope, later discussed in #5123 as both went stale without a resolution
Specific case in snowplow web package snowplow/dbt-snowplow-web#54
The text was updated successfully, but these errors were encountered: