Skip to content

Commit

Permalink
PR feedback: Add exception handler around macro execution, add a mess…
Browse files Browse the repository at this point in the history
…age about what is going on when list_schemas fails
  • Loading branch information
Jacob Beck committed Mar 2, 2020
1 parent c59adc3 commit 6d7e453
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
11 changes: 6 additions & 5 deletions core/dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,11 +961,12 @@ def execute_macro(

macro_function = MacroGenerator(macro, macro_context)

try:
result = macro_function(**kwargs)
finally:
if release:
self.release_connection()
with self.connections.exception_handler(f'macro {macro_name}'):
try:
result = macro_function(**kwargs)
finally:
if release:
self.release_connection()
return result

@classmethod
Expand Down
1 change: 1 addition & 0 deletions core/dbt/task/runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ def list_schemas(db: str) -> List[Tuple[str, str]]:
]

def create_schema(db: str, schema: str) -> None:
assert False
with adapter.connection_named(f'create_{db}_{schema}'):
adapter.create_schema(db, schema)

Expand Down
17 changes: 12 additions & 5 deletions plugins/snowflake/dbt/adapters/snowflake/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from dbt.adapters.snowflake import SnowflakeRelation
from dbt.adapters.snowflake import SnowflakeColumn
from dbt.contracts.graph.manifest import Manifest
from dbt.exceptions import RuntimeException
from dbt.exceptions import RuntimeException, DatabaseException
from dbt.utils import filter_null_values


Expand Down Expand Up @@ -84,10 +84,17 @@ def post_model_hook(
self._use_warehouse(context)

def list_schemas(self, database: str) -> List[str]:
results = self.execute_macro(
LIST_SCHEMAS_MACRO_NAME,
kwargs={'database': database}
)
try:
results = self.execute_macro(
LIST_SCHEMAS_MACRO_NAME,
kwargs={'database': database}
)
except DatabaseException as exc:
msg = (
f'Database error while listing schemas in database '
f'"{database}"\n{exc}'
)
raise RuntimeException(msg)
# this uses 'show terse schemas in database', and the column name we
# want is 'name'

Expand Down

0 comments on commit 6d7e453

Please sign in to comment.