Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: DynamoDB test connection was broken #1491

Merged
merged 1 commit into from
Dec 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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