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/env vars #543

Merged
merged 4 commits into from
Sep 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ def invoke_dbt(parsed):
targets = proj.cfg.get('outputs', {}).keys()
if parsed.target in targets:
proj.cfg['target'] = parsed.target
# make sure we update the target if this is overriden on the cli
proj.compile_and_update_target()
else:
logger.info("Encountered an error while reading the project:")
logger.info(" ERROR Specified target {} is not a valid option "
Expand Down
9 changes: 7 additions & 2 deletions dbt/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def __init__(self, cfg, profiles, profiles_dir, profile_to_load=None,

if self.profile_to_load in self.profiles:
self.cfg.update(self.profiles[self.profile_to_load])
self.compile_and_update_target()

else:
raise DbtProjectError(
"Could not find profile named '{}'"
Expand Down Expand Up @@ -120,15 +122,18 @@ def compile_target(self, target_cfg):
is_str = isinstance(value, dbt.compat.basestring)

if is_str:
node = "config key: '{}'".format(key)
compiled_val = dbt.clients.jinja.get_rendered(value, ctx, node)
compiled_val = dbt.clients.jinja.get_rendered(value, ctx)
else:
compiled_val = value

compiled[key] = compiled_val

return compiled

def compile_and_update_target(self):
target = self.cfg['target']
self.cfg['outputs'][target].update(self.run_environment())
Copy link
Contributor Author

@drewbanin drewbanin Sep 29, 2017

Choose a reason for hiding this comment

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

@cmcarthur i don't like playing with the state here, but I don't want to touch the Project interface. lmk if you disagree


def run_environment(self):
target_name = self.cfg['target']
if target_name in self.cfg['outputs']:
Expand Down
14 changes: 10 additions & 4 deletions test/integration/013_context_var_tests/test_context_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def setUp(self):
DBTIntegrationTest.setUp(self)
os.environ["DBT_TEST_013_ENV_VAR"] = "1"

os.environ["DBT_TEST_013_USER"] = "root"
os.environ["DBT_TEST_013_PASS"] = "password"

self.fields = [
'this',
'this.name',
Expand Down Expand Up @@ -42,13 +45,15 @@ def profile_config(self):
return {
'test': {
'outputs': {
# don't use env_var's here so the integration tests can run
# seed sql statements and the like. default target is used
'dev': {
'type': 'postgres',
'threads': 1,
'host': 'database',
'port': 5432,
'user': 'root',
'pass': 'password',
'user': "root",
'pass': "password",
'dbname': 'dbt',
'schema': self.unique_schema()
},
Expand All @@ -57,8 +62,9 @@ def profile_config(self):
'threads': 1,
'host': 'database',
'port': 5432,
'user': 'root',
'pass': 'password',
# root/password
'user': "{{ env_var('DBT_TEST_013_USER') }}",
'pass': "{{ env_var('DBT_TEST_013_PASS') }}",
'dbname': 'dbt',
'schema': self.unique_schema()
}
Expand Down