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

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

Merged
merged 1 commit into from
Nov 23, 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
15 changes: 7 additions & 8 deletions redash/query_runner/cass.py
Original file line number Diff line number Diff line change
@@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not fully sure if this Error import works well. At least when I tested, it did not work and I have to remove it and replace the reference below by ValueError.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by works well? It wasn't found?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in log file found this trace [2016-11-23 09:44:06,140][PID:18841][WARNING][redash.query_runner] Cassandra query runner enabled but not supported, not registering. Either disable or install missing dependencies. which causes it is import error:

python -c "from cassandra.cluster import Cluster, Error"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name Error
python --version
Python 2.7.6

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right there is no such thing. I just assumed it exists as it was referenced in the code...

@yershalom ?

from cassandra.auth import PlainTextAuthProvider
enabled = True
except ImportError:
enabled = False


class Cassandra(BaseQueryRunner):
noop_query = "SELECT * FROM system"

Expand Down Expand Up @@ -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)
Expand All @@ -86,22 +85,22 @@ def run_query(self, query, user):
json_data = json.dumps(data, cls=JSONEncoder)

error = None

except cassandra.cluster.Error, e:
except Error as e:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as commented above I change it for ValueError

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)

@classmethod
def type(cls):
return "scylla"


register(Cassandra)
register(ScyllaDB)