From 6ba14b852b4ea60e0f13cb121a8cbec4f988d25f Mon Sep 17 00:00:00 2001 From: Connor McArthur Date: Sun, 19 Feb 2017 14:46:20 -0500 Subject: [PATCH 1/2] add optional `role` argument, fix messaging around permissions errors --- Makefile | 2 +- dbt/adapters/snowflake.py | 8 ++++++++ dbt/contracts/connection.py | 3 ++- dbt/main.py | 3 ++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1feba3c0946..ab5c546958b 100644 --- a/Makefile +++ b/Makefile @@ -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..." diff --git a/dbt/adapters/snowflake.py b/dbt/adapters/snowflake.py index ce43dbab965..c89c64fefbb 100644 --- a/dbt/adapters/snowflake.py +++ b/dbt/adapters/snowflake.py @@ -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)) @@ -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 ) diff --git a/dbt/contracts/connection.py b/dbt/contracts/connection.py index 0646c4cd3c2..46aeb90527d 100644 --- a/dbt/contracts/connection.py +++ b/dbt/contracts/connection.py @@ -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 @@ -28,6 +28,7 @@ Required('database'): str, Required('schema'): str, Required('warehouse'): str, + Optional('role'): str, }) credentials_mapping = { diff --git a/dbt/main.py b/dbt/main.py index 49e2919a13c..99710aaa1c7 100644 --- a/dbt/main.py +++ b/dbt/main.py @@ -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) From a04ba723684db3f6036dd6463aa7cc587b122afa Mon Sep 17 00:00:00 2001 From: Connor McArthur Date: Mon, 20 Feb 2017 09:43:22 -0500 Subject: [PATCH 2/2] update sample.profiles.yml and CHANGELOG.md to reflect role setting --- CHANGELOG.md | 6 ++++++ sample.profiles.yml | 2 ++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70121f00531..57ec34d7433 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/sample.profiles.yml b/sample.profiles.yml index 803026a70a3..7d539bb6a53 100644 --- a/sample.profiles.yml +++ b/sample.profiles.yml @@ -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