Skip to content

Commit

Permalink
Merge pull request #2062 from fishtown-analytics/fix/overwrite-clobbe…
Browse files Browse the repository at this point in the history
…r-config-fields

Overwrite clobber config fields
  • Loading branch information
drewbanin authored Jan 27, 2020
2 parents b9f8ded + 1f74980 commit fdfcd4c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/dbt/source_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ def __init__(self, active_project, own_project, fqn, node_type):
def _merge(self, *configs):
merged_config = {}
for config in configs:
# Do not attempt to deep merge clobber fields
config = config.copy()
clobber = {
key: config.pop(key) for key in list(config.keys())
if key in (self.ClobberFields | self.AdapterSpecificConfigs)
}
intermediary_merged = deep_merge(
merged_config.copy(), config.copy()
merged_config, config
)
intermediary_merged.update(clobber)

merged_config.update(intermediary_merged)
return merged_config
Expand Down
22 changes: 22 additions & 0 deletions test/unit/test_source_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,28 @@ def test__source_config_multiple_calls(self):
}
self.assertEqual(cfg.config, expect)

def test__source_config_merge(self):
self.root_project_config.models = {'sort': ['a', 'b']}
cfg = SourceConfig(self.root_project_config, self.root_project_config,
['root', 'x'], NodeType.Model)
cfg.update_in_model_config({
'materialized': 'something',
'sort': ['d', 'e']
})
expect = {
'column_types': {},
'enabled': True,
'materialized': 'something',
'post-hook': [],
'pre-hook': [],
'persist_docs': {},
'quoting': {},
'sort': ['d', 'e'],
'tags': [],
'vars': {},
}
self.assertEqual(cfg.config, expect)

def test_source_config_all_keys_accounted_for(self):
used_keys = frozenset(SourceConfig.AppendListFields) | \
frozenset(SourceConfig.ExtendDictFields) | \
Expand Down

0 comments on commit fdfcd4c

Please sign in to comment.