Skip to content
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

fix var precedence from cli, add tests #739

Merged
merged 2 commits into from
Apr 26, 2018
Merged

Conversation

drewbanin
Copy link
Contributor

@drewbanin drewbanin commented Apr 14, 2018

fixes #710

Big TODO here -- why didn't these tests fail previously? Does this PR change behavior beyond the precedence fix?

@@ -25,7 +25,9 @@ def test__cli_vars_longform(self):
}
}
self.run_dbt(["run", "--vars", yaml.dump(cli_vars)])
self.run_dbt(["test"])

# TODO : This change in sensible, but why did it not fail before??
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you figure it out? you should probably figure it out and remove this comment, or just remove it hah

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah -- this worked incorrectly before. The test should have failed, but the vars were stored in a global somewhere so it looked like they were supplied again. I couldn't quite figure out why that happened, but can dig some more if you feel strongly about it.

It's only an issue since we're invoking dbt as a lib from the integration tests

local_vars = model.config.get('vars', {})

self.local_vars = local_vars.copy()
self.local_vars.update(overrides)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have merge and deep merge fns in utils, use:

self.local_vars = merge(local_vars, overrides)

instead

if 'vars' not in self.cfg['models']:
self.cfg['models']['vars'] = {}

self.cfg['models']['vars'].update(global_vars)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove this and add global_vars below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, this code updated the cfg['models']['vars'] dict with vars defined on the CLI. These vars served as the "base" variables, and were overridden by other variables defined in the models: section of the dbt_project.yml file. My solution here was to store the cli vars separately, then merge them on top of any dbt_project.yml-based configs in the Var object. Can you think of a better way to do this?

@drewbanin
Copy link
Contributor Author

I synced up with @cmcarthur to discuss these changes. Got the :shipit:, merging

@drewbanin drewbanin merged commit 0a797af into development Apr 26, 2018
@drewbanin drewbanin deleted the fix/var-precedence branch September 19, 2018 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants