Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow macros to return non-text values #571

Merged
merged 1 commit into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dbt/clients/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def call(*args, **kwargs):

try:
return macro(*args, **kwargs)
except dbt.exceptions.MacroReturn as e:
return e.value
except (TypeError,
jinja2.exceptions.TemplateRuntimeError) as e:
dbt.exceptions.raise_compiler_error(
Expand Down
5 changes: 5 additions & 0 deletions dbt/context/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ def fn(string, default=None):
return fn


def _return(value):
raise dbt.exceptions.MacroReturn(value)


def generate(model, project, flat_graph, provider=None):
"""
Not meant to be called directly. Call with either:
Expand Down Expand Up @@ -282,6 +286,7 @@ def generate(model, project, flat_graph, provider=None):
"post_hooks": post_hooks,
"pre_hooks": pre_hooks,
"ref": provider.ref(model, project, profile, flat_graph),
"return": _return,
"schema": model.get('schema', schema),
"sql": model.get('injected_sql'),
"sql_now": adapter.date_function(),
Expand Down
9 changes: 9 additions & 0 deletions dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ class Exception(BaseException):
pass


class MacroReturn(BaseException):
"""
Hack of all hacks
"""

def __init__(self, value):
self.value = value


class InternalException(Exception):
pass

Expand Down