Skip to content

Commit

Permalink
Fix generate_schema_name macro for multiple args
Browse files Browse the repository at this point in the history
Add repeat flag to warn_or_error to suppress duplicate warnings
Add a warning if a user's macro does not take a second argument
  • Loading branch information
Jacob Beck committed May 30, 2019
1 parent 68782b7 commit 8af2a77
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 7 additions & 1 deletion core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,16 @@ def raise_not_implemented(msg):
raise NotImplementedException(msg)


def warn_or_error(msg, node=None, log_fmt=None):
_REPEAT_MESSAGE_CACHE = set()


def warn_or_error(msg, node=None, log_fmt=None, repeat=True):
if dbt.flags.WARN_ERROR:
raise_compiler_error(msg, node)
else:
if not repeat and msg in _REPEAT_MESSAGE_CACHE:
return
_REPEAT_MESSAGE_CACHE.add(msg)
if log_fmt is not None:
msg = log_fmt.format(msg)
logger.warning(msg)
Expand Down
16 changes: 15 additions & 1 deletion core/dbt/parser/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,21 @@ def _update_parsed_node_info(self, parsed_node, config):
# definition, not the current package
schema_override = config.config.get('schema')
get_schema = self.get_schema_func()
parsed_node.schema = get_schema(schema_override, parsed_node).strip()
try:
schema = get_schema(schema_override, parsed_node)
except dbt.exceptions.CompilationException as exc:
too_many_args = (
"macro 'dbt_macro__generate_schema_name' takes not more than "
"1 argument(s)"
)
if too_many_args not in str(exc):
raise
msg = ('The generate_schema_name macro does not accept a second '
'argument. This form is deprecated as of 0.14.0')
dbt.exceptions.warn_or_error(msg, node=parsed_node, repeat=False,
log_fmt='WARNING: {}')
schema = get_schema(schema_override)
parsed_node.schema = schema.strip()

alias_override = config.config.get('alias')
get_alias = self.get_alias_func()
Expand Down

0 comments on commit 8af2a77

Please sign in to comment.