diff --git a/core/dbt/contracts/graph/model_config.py b/core/dbt/contracts/graph/model_config.py index 89cbc2bb0a7..1ff317591dd 100644 --- a/core/dbt/contracts/graph/model_config.py +++ b/core/dbt/contracts/graph/model_config.py @@ -445,9 +445,9 @@ class TestConfig(NodeConfig): store_failures: Optional[bool] = None where: Optional[str] = None limit: Optional[int] = None - fail_calc: str = "count(*)" - warn_if: str = "!= 0" - error_if: str = "!= 0" + fail_calc: str = 'count(*)' + warn_if: str = '!= 0' + error_if: str = '!= 0' @classmethod def same_contents( diff --git a/core/dbt/parser/schema_test_builders.py b/core/dbt/parser/schema_test_builders.py index b3af2f5368a..0c600bab98b 100644 --- a/core/dbt/parser/schema_test_builders.py +++ b/core/dbt/parser/schema_test_builders.py @@ -280,12 +280,15 @@ def extract_test_args(test, name=None) -> Tuple[str, Dict[str, Any]]: test_args['column_name'] = name return test_name, test_args + @property def enabled(self) -> Optional[bool]: return self.modifiers.get('enabled') + @property def alias(self) -> Optional[str]: return self.modifiers.get('alias') + @property def severity(self) -> Optional[str]: sev = self.modifiers.get('severity') if sev: @@ -293,21 +296,27 @@ def severity(self) -> Optional[str]: else: return None + @property def store_failures(self) -> Optional[bool]: return self.modifiers.get('store_failures') + @property def where(self) -> Optional[str]: return self.modifiers.get('where') + @property def limit(self) -> Optional[int]: return self.modifiers.get('limit') + @property def warn_if(self) -> Optional[str]: return self.modifiers.get('warn_if') + @property def error_if(self) -> Optional[str]: return self.modifiers.get('error_if') + @property def fail_calc(self) -> Optional[str]: return self.modifiers.get('fail_calc') @@ -346,7 +355,8 @@ def get_test_name(self) -> Tuple[str, str]: def construct_config(self) -> str: configs = ",".join([ - f"{key}=" + (f"'{value}'" if isinstance(value, str) else str(value)) + f"{key}=" + (f"'{value}'" if isinstance(value, str) + else str(value)) for key, value in self.modifiers.items() ]) diff --git a/core/dbt/parser/schemas.py b/core/dbt/parser/schemas.py index 41f173cd432..0178ac703f0 100644 --- a/core/dbt/parser/schemas.py +++ b/core/dbt/parser/schemas.py @@ -489,32 +489,32 @@ def render_test_update(self, node, config, builder): ['macro.dbt.test_not_null', 'macro.dbt.test_unique']): self.update_parsed_node(node, config) # manually set configs - if builder.severity() is not None: - node.unrendered_config['severity'] = builder.severity() - node.config['severity'] = builder.severity() - if builder.enabled() is not None: - node.unrendered_config['enabled'] = builder.enabled() - node.config['enabled'] = builder.enabled() # note: this does not respect generate_alias_name() macro - if builder.alias() is not None: - node.unrendered_config['alias'] = builder.alias() - node.config['alias'] = builder.alias() - node.alias = builder.alias() - if builder.where() is not None: - node.unrendered_config['where'] = builder.where() - node.config['where'] = builder.where() - if builder.limit() is not None: - node.unrendered_config['limit'] = builder.limit() - node.config['limit'] = builder.limit() - if builder.warn_if() is not None: - node.unrendered_config['warn_if'] = builder.warn_if() - node.config['warn_if'] = builder.warn_if() - if builder.error_if() is not None: - node.unrendered_config['error_if'] = builder.error_if() - node.config['error_if'] = builder.error_if() - if builder.fail_calc() is not None: - node.unrendered_config['fail_calc'] = builder.fail_calc() - node.config['fail_calc'] = builder.fail_calc() + if builder.alias is not None: + node.unrendered_config['alias'] = builder.alias + node.config['alias'] = builder.alias + node.alias = builder.alias + if builder.severity is not None: + node.unrendered_config['severity'] = builder.severity + node.config['severity'] = builder.severity + if builder.enabled is not None: + node.unrendered_config['enabled'] = builder.enabled + node.config['enabled'] = builder.enabled + if builder.where is not None: + node.unrendered_config['where'] = builder.where + node.config['where'] = builder.where + if builder.limit is not None: + node.unrendered_config['limit'] = builder.limit + node.config['limit'] = builder.limit + if builder.warn_if is not None: + node.unrendered_config['warn_if'] = builder.warn_if + node.config['warn_if'] = builder.warn_if + if builder.error_if is not None: + node.unrendered_config['error_if'] = builder.error_if + node.config['error_if'] = builder.error_if + if builder.fail_calc is not None: + node.unrendered_config['fail_calc'] = builder.fail_calc + node.config['fail_calc'] = builder.fail_calc # source node tests are processed at patch_source time if isinstance(builder.target, UnpatchedSourceDefinition): sources = [builder.target.fqn[-2], builder.target.fqn[-1]]