Skip to content

Commit

Permalink
Merge pull request #2575 from fishtown-analytics/fix/backport-aliasing
Browse files Browse the repository at this point in the history
backport aliases in config fix
  • Loading branch information
beckjake authored Jun 19, 2020
2 parents 593e86c + 098d05c commit 19378ab
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Parallel RPC requests no longer step on each others' arguments ([[#2484](https://github.com/fishtown-analytics/dbt/issues/2484), [#2554](https://github.com/fishtown-analytics/dbt/pull/2554)])
- `persist_docs` now takes into account descriptions for nested columns in bigquery ([#2549](https://github.com/fishtown-analytics/dbt/issues/2549), [#2550](https://github.com/fishtown-analytics/dbt/pull/2550))
- On windows (depending upon OS support), dbt no longer fails with errors when writing artifacts ([#2558](https://github.com/fishtown-analytics/dbt/issues/2558), [#2566](https://github.com/fishtown-analytics/dbt/pull/2566))
- dbt again respects config aliases in config() calls and dbt_project.yml ([#2557](https://github.com/fishtown-analytics/dbt/issues/2557), [#2559](https://github.com/fishtown-analytics/dbt/pull/2559), [#2575](https://github.com/fishtown-analytics/dbt/pull/2575))

Contributors:
- [@bodschut](https://github.com/bodschut) ([#2550](https://github.com/fishtown-analytics/dbt/pull/2550))
Expand Down
3 changes: 2 additions & 1 deletion core/dbt/context/context_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ def active_project_configs(
def _update_from_config(
self, result: T, partial: Dict[str, Any], validate: bool = False
) -> T:
translated = self.active_project.credentials.translate_aliases(partial)
return result.update_from(
partial,
translated,
self.active_project.credentials.type,
validate=validate
)
Expand Down
8 changes: 5 additions & 3 deletions test/integration/040_override_database_test/models/view_2.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{{
config(database=var('alternate_db'))
}}
{%- if target.type == 'bigquery' -%}
{{ config(project=var('alternate_db')) }}
{%- else -%}
{{ config(database=var('alternate_db')) }}
{%- endif -%}
select * from {{ ref('seed') }}
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,45 @@ def test_snowflake_database_override(self):
self.run_database_override()


class TestProjectModelOverride(BaseOverrideDatabase):
class BaseTestProjectModelOverride(BaseOverrideDatabase):
# this is janky, but I really want to access self.default_database in
# project_config
@property
def default_database(self):
target = self._profile_config['test']['target']
profile = self._profile_config['test']['outputs'][target]
for key in ['database', 'project', 'dbname']:
if key in profile:
database = profile[key]
if self.adapter_type == 'snowflake':
return database.upper()
return database
assert False, 'No profile database found!'

def run_database_override(self):
self.run_dbt_notstrict(['seed'])
self.assertEqual(len(self.run_dbt_notstrict(['run'])), 4)
self.assertExpectedRelations()

def assertExpectedRelations(self):
if self.adapter_type == 'snowflake':
func = lambda x: x.upper()
else:
func = lambda x: x

self.use_default_project({
self.assertManyRelationsEqual([
(func('seed'), self.unique_schema(), self.default_database),
(func('view_2'), self.unique_schema(), self.alternative_database),
(func('view_1'), self.unique_schema(), self.alternative_database),
(func('view_3'), self.unique_schema(), self.default_database),
(func('view_4'), self.unique_schema(), self.alternative_database),
])


class TestProjectModelOverride(BaseTestProjectModelOverride):
@property
def project_config(self):
return {
'config-version': 2,
'vars': {
'alternate_db': self.alternative_database,
Expand All @@ -119,17 +150,17 @@ def run_database_override(self):
}
}
},
})
self.run_dbt_notstrict(['seed'])

self.assertEqual(len(self.run_dbt_notstrict(['run'])), 4)
self.assertManyRelationsEqual([
(func('seed'), self.unique_schema(), self.default_database),
(func('view_2'), self.unique_schema(), self.alternative_database),
(func('view_1'), self.unique_schema(), self.alternative_database),
(func('view_3'), self.unique_schema(), self.default_database),
(func('view_4'), self.unique_schema(), self.alternative_database),
])
'data-paths': ['data'],
'vars': {
'alternate_db': self.alternative_database,
},
'quoting': {
'database': True,
},
'seeds': {
'quote_columns': False,
}
}

@use_profile('bigquery')
def test_bigquery_database_override(self):
Expand All @@ -140,6 +171,39 @@ def test_snowflake_database_override(self):
self.run_database_override()


class TestProjectModelAliasOverride(BaseTestProjectModelOverride):
@property
def project_config(self):
return {
'config-version': 2,
'vars': {
'alternate_db': self.alternative_database,
},
'models': {
'project': self.alternative_database,
'test': {
'subfolder': {
'project': self.default_database,
}
}
},
'data-paths': ['data'],
'vars': {
'alternate_db': self.alternative_database,
},
'quoting': {
'database': True,
},
'seeds': {
'quote_columns': False,
}
}

@use_profile('bigquery')
def test_bigquery_project_override(self):
self.run_database_override()


class TestProjectSeedOverride(BaseOverrideDatabase):
def run_database_override(self):
if self.adapter_type == 'snowflake':
Expand Down
2 changes: 2 additions & 0 deletions test/integration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,8 @@ def assertManyRelationsEqual(self, relations, default_schema=None, default_datab
first_columns = None
for relation in specs:
key = (relation.database, relation.schema, relation.identifier)
# get a good error here instead of a hard-to-diagnose KeyError
self.assertIn(key, column_specs, f'No columns found for {key}')
columns = column_specs[key]
if first_columns is None:
first_columns = columns
Expand Down

0 comments on commit 19378ab

Please sign in to comment.