[Cassandra] Fix: cassandra.cluster.Error wasn't imported

Fixed #1422.
This commit is contained in:
Arik Fraimovich 2016-11-23 10:51:06 +02:00 committed by GitHub
parent e6482cffab
commit 52c71bc740

View File

@ -1,18 +1,19 @@
import json
import sys
import logging
from redash.query_runner import *
from redash.query_runner import BaseQueryRunner, register
from redash.utils import JSONEncoder
logger = logging.getLogger(__name__)
try:
from cassandra.cluster import Cluster
from cassandra.cluster import Cluster, Error
from cassandra.auth import PlainTextAuthProvider
enabled = True
except ImportError:
enabled = False
class Cassandra(BaseQueryRunner):
noop_query = "SELECT * FROM system"
@ -61,11 +62,9 @@ class Cassandra(BaseQueryRunner):
return results, error
def run_query(self, query, user):
from cassandra.cluster import Cluster
connection = None
try:
if self.configuration.get('username', '') and self.configuration.get('password', ''):
from cassandra.auth import PlainTextAuthProvider
auth_provider = PlainTextAuthProvider(username='{}'.format(self.configuration.get('username', '')),
password='{}'.format(self.configuration.get('password', '')))
connection = Cluster([self.configuration.get('host', '')], auth_provider=auth_provider)
@ -86,16 +85,15 @@ class Cassandra(BaseQueryRunner):
json_data = json.dumps(data, cls=JSONEncoder)
error = None
except cassandra.cluster.Error, e:
except Error as e:
error = e.args[1]
except KeyboardInterrupt:
error = "Query cancelled by user."
return json_data, error
class ScyllaDB(Cassandra):
class ScyllaDB(Cassandra):
def __init__(self, configuration):
super(ScyllaDB, self).__init__(configuration)
@ -103,5 +101,6 @@ class ScyllaDB(Cassandra):
def type(cls):
return "scylla"
register(Cassandra)
register(ScyllaDB)