diff --git a/dbt/main.py b/dbt/main.py index a5a18fa471f..44e424eaabe 100644 --- a/dbt/main.py +++ b/dbt/main.py @@ -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 " diff --git a/dbt/project.py b/dbt/project.py index 8e3ec0f72bf..6cf58387cfb 100644 --- a/dbt/project.py +++ b/dbt/project.py @@ -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 '{}'" @@ -120,8 +122,7 @@ 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 @@ -129,6 +130,10 @@ def compile_target(self, target_cfg): return compiled + def compile_and_update_target(self): + target = self.cfg['target'] + self.cfg['outputs'][target].update(self.run_environment()) + def run_environment(self): target_name = self.cfg['target'] if target_name in self.cfg['outputs']: diff --git a/test/integration/013_context_var_tests/test_context_vars.py b/test/integration/013_context_var_tests/test_context_vars.py index b2e8fe3df79..dc19d3583c8 100644 --- a/test/integration/013_context_var_tests/test_context_vars.py +++ b/test/integration/013_context_var_tests/test_context_vars.py @@ -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', @@ -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() }, @@ -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() }