From e06740d5ddee9af90d842d20b92704c3192d2f34 Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Wed, 23 Nov 2016 10:51:06 +0200 Subject: [PATCH] [Cassandra] Fix: cassandra.cluster.Error wasn't imported Fixed #1422. --- query_runner/cass.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/query_runner/cass.py b/query_runner/cass.py index 9da686800f..b8610ea13c 100644 --- a/query_runner/cass.py +++ b/query_runner/cass.py @@ -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 @@ def _get_tables(self, schema): 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 @@ def run_query(self, query, user): 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 @@ def __init__(self, configuration): def type(cls): return "scylla" + register(Cassandra) register(ScyllaDB)