Skip to content

Commit

Permalink
Merge pull request getredash#1491 from getredash/v1fixes
Browse files Browse the repository at this point in the history
Fix: DynamoDB test connection was broken
  • Loading branch information
arikfr authored Dec 27, 2016
2 parents 8d92702 + 1388e76 commit ea12dc4
Showing 1 changed file with 14 additions and 28 deletions.
42 changes: 14 additions & 28 deletions redash/query_runner/dynamodb_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@


class DynamoDBSQL(BaseSQLQueryRunner):
noop_query = "SELECT 1"

@classmethod
def configuration_schema(cls):
return {
Expand All @@ -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
Expand All @@ -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)+';')

Expand All @@ -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:
Expand Down

0 comments on commit ea12dc4

Please sign in to comment.