Skip to content

Commit

Permalink
snowflake: add optional role argument, fix messaging around permiss…
Browse files Browse the repository at this point in the history
…ions errors (#291)
  • Loading branch information
cmcarthur authored Feb 20, 2017
1 parent ff3aa6e commit 36b26d8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## dbt 0.7.1 (unreleased)

#### New Features

- profiles.yml now supports Snowflake `role` as an option ([#291](https://github.com/analyst-collective/dbt/pull/291))

## dbt 0.7.0 (February 9, 2017)

### Overview
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
changed_tests := `git status --porcelain | grep '^\(M\| M\|A\| A\)' | awk '{ print $$2 }' | grep '\/test_[a-zA-Z_\-\.]\+.py'`

install:
pip install .
pip install --upgrade .

test:
@echo "Full test run starting..."
Expand Down
8 changes: 8 additions & 0 deletions dbt/adapters/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ def exception_handler(connection, cursor, model_name, query):
except snowflake.connector.errors.ProgrammingError as e:
if 'Empty SQL statement' in e.msg:
logger.debug("got empty sql statement, moving on")
elif 'This session does not have a current database' in e.msg:
handle.rollback()
raise dbt.exceptions.FailedToConnectException(
('{}\n\nThis error sometimes occurs when invalid credentials '
'are provided, or when your default role does not have '
'access to use the specified database. Please double check '
'your profile and try again.').format(str(e)))
else:
handle.rollback()
raise dbt.exceptions.ProgrammingException(str(e))
Expand Down Expand Up @@ -96,6 +103,7 @@ def open_connection(cls, connection):
database=credentials.get('database'),
schema=credentials.get('schema'),
warehouse=credentials.get('warehouse'),
role=credentials.get('role', None),
autocommit=False
)

Expand Down
3 changes: 2 additions & 1 deletion dbt/contracts/connection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from voluptuous import Schema, Required, All, Any, Extra, Range
from voluptuous import Schema, Required, All, Any, Extra, Range, Optional
from voluptuous.error import MultipleInvalid

from dbt.exceptions import ValidationException
Expand Down Expand Up @@ -28,6 +28,7 @@
Required('database'): str,
Required('schema'): str,
Required('warehouse'): str,
Optional('role'): str,
})

credentials_mapping = {
Expand Down
3 changes: 2 additions & 1 deletion dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def run_from_args(parsed):
dbt.tracking.track_invocation_end(
project=proj, args=parsed, result_type="ok", result=None
)
except dbt.exceptions.NotImplementedException as e:
except (dbt.exceptions.NotImplementedException,
dbt.exceptions.FailedToConnectException) as e:
logger.info('ERROR: {}'.format(e))
dbt.tracking.track_invocation_end(
project=proj, args=parsed, result_type="error", result=str(e)
Expand Down
2 changes: 2 additions & 0 deletions sample.profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ evil-corp:
# i.e. evilcorp.snowflakecomputing.com
user: elliot
password: pa55word
role: SYSADMIN # optional, the snowflake role you want to use
# when connecting
database: db
warehouse: warehouse
schema: analytics # use the prod schema instead
Expand Down

0 comments on commit 36b26d8

Please sign in to comment.