From 1388e76b48781cba9f9ae5132a9363bdd12b214b Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Tue, 27 Dec 2016 14:47:12 +0200 Subject: [PATCH] Fix: DynamoDB test connection was broken --- redash/query_runner/dynamodb_sql.py | 42 ++++++++++------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/redash/query_runner/dynamodb_sql.py b/redash/query_runner/dynamodb_sql.py index 1ffe0df22c..503b52759d 100644 --- a/redash/query_runner/dynamodb_sql.py +++ b/redash/query_runner/dynamodb_sql.py @@ -34,8 +34,6 @@ class DynamoDBSQL(BaseSQLQueryRunner): - noop_query = "SELECT 1" - @classmethod def configuration_schema(cls): return { @@ -45,29 +43,21 @@ def configuration_schema(cls): "type": "string", "default": "us-east-1" }, - "host": { - "type": "string", - "default": "Use for non standard endpoints." - }, - "port": { - "type": "number", - "default": 80 - }, "access_key": { "type": "string", }, "secret_key": { "type": "string", - }, - "is_secure": { - "type": "boolean", - "default": False, } }, "required": ["access_key", "secret_key"], "secret": ["secret_key"] } + def test_connection(self): + engine = self._connect() + list(engine.connection.list_tables()) + @classmethod def annotate_query(cls): return False @@ -93,24 +83,20 @@ def _connect(self): if config.get('host') == '': config['host'] = None - return engine, engine.connect(**config) + engine.connect(**config) - def _get_tables(self, schema): - - try: - engine, _ = self._connect() + return engine - for table in engine.describe_all(): - schema[table.name] = {'name': table.name, 'columns': table.attrs.keys()} + def _get_tables(self, schema): + engine = self._connect() - except Exception as e: - logging.exception(e) - raise sys.exc_info()[1], None, sys.exc_info()[2] + for table in engine.describe_all(): + schema[table.name] = {'name': table.name, 'columns': table.attrs.keys()} def run_query(self, query, user): - connection = None + engine = None try: - engine, connection = self._connect() + engine = self._connect() res_dict = engine.execute(query if str(query).endswith(';') else str(query)+';') @@ -137,8 +123,8 @@ def run_query(self, query, user): error = e.message json_data = None except KeyboardInterrupt: - if connection: - connection.cancel() + if engine and engine.connection: + engine.connection.cancel() error = "Query cancelled by user." json_data = None except Exception as e: