-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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,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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as commented above I change it for |
||
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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 byValueError
.There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:There was a problem hiding this comment.
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 ?