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

Handle undefined variables in jinja better (#935) #1086

Merged
merged 3 commits into from
Oct 23, 2018
Merged
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
23 changes: 13 additions & 10 deletions dbt/clients/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,8 @@ class ParserMacroCapture(jinja2.Undefined):
"""
This class sets up the parser to capture macros.
"""
def __init__(self, hint=None, obj=None, name=None,
exc=None):
super(jinja2.Undefined, self).__init__()
def __init__(self, hint=None, obj=None, name=None, exc=None):
super(ParserMacroCapture, self).__init__(hint=hint, name=name)
self.node = node
self.name = name
self.package_name = node.get('package_name')
Expand All @@ -211,18 +210,22 @@ def __deepcopy__(self, memo):
self.node.get('original_file_path'))

logger.debug(
'A ParserMacroCapture has been deecopy()d, invalid reference '
'to "{}" in node {}.{} (source path: {})'
'dbt encountered an undefined variable, "{}" in node {}.{} '
'(source path: {})'
.format(self.name, self.node.get('package_name'),
self.node.get('name'),
path))
self.node.get('name'), path))

# match jinja's message
dbt.exceptions.raise_compiler_error(
'dbt has detected at least one invalid reference in {}.{}. '
'Check logs for more information'
.format(self.node.get('package_name'), self.node.get('name'))
"{!r} is undefined".format(self.name),
node=self.node
)

def __getitem__(self, name):
# Propagate the undefined value if a caller accesses this as if it
# were a dictionary
return self

def __getattr__(self, name):
if name == 'name' or _is_dunder_name(name):
raise AttributeError(
Expand Down