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

fix commit messages by using the stack properly (#2073) #2238

Merged
merged 1 commit into from
Mar 25, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Fixes
- When a jinja value is undefined, give a helpful error instead of failing with cryptic "cannot pickle ParserMacroCapture" errors ([#2110](https:/fishtown-analytics/dbt/issues/2110), [#2184](https:/fishtown-analytics/dbt/pull/2184))
- Added timeout to registry download call ([#2195](https:/fishtown-analytics/dbt/issues/2195), [#2228](https:/fishtown-analytics/dbt/pull/2228))
- When a macro is called with invalid arguments, include the calling model in the output ([#2073](https:/fishtown-analytics/dbt/issues/2073), [#2238](https:/fishtown-analytics/dbt/pull/2238))

Contributors:
- [@raalsky](https:/Raalsky) ([#2224](https:/fishtown-analytics/dbt/pull/2224), [#2228](https:/fishtown-analytics/dbt/pull/2228))
Expand Down
3 changes: 3 additions & 0 deletions core/dbt/clients/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ def catch_jinja(node=None) -> Iterator[None]:
raise CompilationException(str(e), node) from e
except jinja2.exceptions.UndefinedError as e:
raise CompilationException(str(e), node) from e
except CompilationException as exc:
exc.add_node(node)
raise


def parse(string):
Expand Down
9 changes: 7 additions & 2 deletions core/dbt/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def __init__(self, msg, node=None):
self.node = node
self.msg = msg

def add_node(self, node=None):
if node is not None and node is not self.node:
if self.node is not None:
self.stack.append(self.node)
self.node = node

@property
def type(self):
return 'Runtime'
Expand Down Expand Up @@ -849,8 +855,7 @@ def inner(*args, **kwargs):
try:
return func(*args, **kwargs)
except RuntimeException as exc:
if exc.node is None:
exc.node = model
exc.add_node(model)
raise exc
return inner
return wrap
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/node_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def compile_and_execute(self, manifest, ctx):

def _handle_catchable_exception(self, e, ctx):
if e.node is None:
e.node = ctx.node
e.add_node(ctx.node)

logger.debug(str(e), exc_info=True)
return str(e)
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def parse_block(self, block: FullBlock) -> Iterable[ParsedDocumentation]:
try:
template = get_template(block.contents, {})
except CompilationException as e:
e.node = base_node
e.add_node(base_node)
raise
all_docs = list(self._parse_template_docs(template, base_node))
if len(all_docs) != 1:
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def parse_unparsed_macros(
try:
ast = jinja.parse(block.full_block)
except CompilationException as e:
e.node = base_node
e.add_node(base_node)
raise e

macro_nodes = list(ast.find_all(jinja2.nodes.Macro))
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def extract_blocks(self, source_file: FileBlock) -> Iterable[BlockTag]:

except CompilationException as exc:
if exc.node is None:
exc.node = source_file
exc.add_node(source_file)
raise

def __iter__(self) -> Iterator[BlockSearchResult]:
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/rpc/node_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def handle_exception(self, e, ctx):
logger.debug('Got an exception: {}'.format(e), exc_info=True)
if isinstance(e, dbt.exceptions.Exception):
if isinstance(e, dbt.exceptions.RuntimeException):
e.node = ctx.node
e.add_node(ctx.node)
return dbt_error(e)
elif isinstance(e, RPCException):
return e
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro some_macro(arg) %}
{{ arg }}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{ some_macro(invalid='test') }}
select 1 as id
33 changes: 33 additions & 0 deletions test/integration/011_invalid_model_tests/test_invalid_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from test.integration.base import DBTIntegrationTest, use_profile
import os


class TestInvalidDisabledModels(DBTIntegrationTest):
Expand Down Expand Up @@ -45,3 +46,35 @@ def test_postgres_view_with_incremental_attributes(self):
self.run_dbt()

self.assertIn('which was not found', str(exc.exception))


class TestInvalidMacroCall(DBTIntegrationTest):
@property
def schema(self):
return "invalid_models_011"

@property
def models(self):
return "models-4"

@staticmethod
def dir(path):
return path.lstrip("/")

@property
def project_config(self):
return {
'macro-paths': [self.dir('bad-macros')],
}

@use_profile('postgres')
def test_postgres_call_invalid(self):
with self.assertRaises(Exception) as exc:
self.run_dbt(['compile'])


macro_path = os.path.join('bad-macros', 'macros.sql')
model_path = os.path.join('models-4', 'bad_macro.sql')

self.assertIn(f'> in macro some_macro ({macro_path})', str(exc.exception))
self.assertIn(f'> called by model bad_macro ({model_path})', str(exc.exception))