Skip to content

Commit

Permalink
Add 'meta' to test config
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Jul 30, 2021
1 parent 8b089af commit 9938983
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
5 changes: 1 addition & 4 deletions core/dbt/contracts/graph/parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,14 @@ def patch(self, patch: 'ParsedNodePatch'):
"""Given a ParsedNodePatch, add the new information to the node."""
# explicitly pick out the parts to update so we don't inadvertently
# step on the model name or anything
# Note: config should already be updated
self.patch_path: Optional[str] = patch.file_id
# update created_at so process_docs will run in partial parsing
self.created_at = int(time.time())
self.description = patch.description
self.columns = patch.columns
self.meta = patch.meta
self.docs = patch.docs
if patch.config:
pass # for now. reorganizing code...
# we need to re-do the 'update_parsed_node_config' steps, i.e.
# apply dbt_project config, patch config, and model file config
if flags.STRICT_MODE:
# It seems odd that an instance can be invalid
# Maybe there should be validation or restrictions
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def render_update(
experimentally_parsed: Dict[str, List[Any]] = py_extract_from_source(node.raw_sql)

# second config format
config_call_dict: Dict[str, str] = {}
config_call_dict: Dict[str, Any] = {}
for c in experimentally_parsed['configs']:
ContextConfig._add_config_call(config_call_dict, {c[0]: c[1]})

Expand Down
8 changes: 7 additions & 1 deletion core/dbt/parser/schema_test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class TestBuilder(Generic[Testable]):
# kwargs representing test configs
MODIFIER_ARGS = (
'severity', 'tags', 'enabled', 'where', 'limit', 'warn_if', 'error_if',
'fail_calc', 'store_failures'
'fail_calc', 'store_failures', 'meta',
)

def __init__(
Expand Down Expand Up @@ -320,6 +320,10 @@ def error_if(self) -> Optional[str]:
def fail_calc(self) -> Optional[str]:
return self.modifiers.get('fail_calc')

@property
def meta(self) -> Optional[dict]:
return self.modifiers.get('meta')

def get_static_config(self):
config = {}
if self.alias is not None:
Expand All @@ -340,6 +344,8 @@ def get_static_config(self):
config['fail_calc'] = self.fail_calc
if self.store_failures is not None:
config['store_failures'] = self.store_failures
if self.meta is not None:
config['meta'] = self.meta
return config

def tags(self) -> List[str]:
Expand Down
7 changes: 7 additions & 0 deletions test/integration/039_config_test/models-alt/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ models:
meta:
owner: 'Julie Smith'
materialization: view
columns:
- name: id
tests:
- not_null:
meta:
owner: 'Simple Simon'

Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,13 @@ def test_postgres_config_layering(self):
models = self.get_models_in_schema()
self.assertEqual(models['model'], 'table')
self.assertTablesEqual('some_seed', 'model')
# look for test meta
schema_file_id = model_node.patch_path
schema_file = manifest.files[schema_file_id]
tests = schema_file.get_tests('models', 'model')
self.assertIn(tests[0], manifest.nodes)
test = manifest.nodes[tests[0]]
expected_meta = {'owner': 'Simple Simon'}
self.assertEqual(test.config.meta, expected_meta)


0 comments on commit 9938983

Please sign in to comment.