From 52c71bc740e1f8f856e2399202359bffebe1a006 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. --- redash/query_runner/cass.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/redash/query_runner/cass.py b/redash/query_runner/cass.py index 9da68680..b8610ea1 100644 --- a/redash/query_runner/cass.py +++ b/redash/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 @@ 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)