diff --git a/redash/query_runner/mongodb.py b/redash/query_runner/mongodb.py index 87468e628b..8639ae125f 100644 --- a/redash/query_runner/mongodb.py +++ b/redash/query_runner/mongodb.py @@ -68,8 +68,8 @@ def configuration_schema(cls): 'type': 'string', 'title': 'Replica Set Name' }, - 'required': ['connectionString'] - } + }, + 'required': ['connectionString'] } @classmethod @@ -132,8 +132,8 @@ def run_query(self, query): s = None if "sort" in query_data and query_data["sort"]: s = [] - for field_name in query_data["sort"]: - s.append((field_name, query_data["sort"][field_name])) + for field_data in query_data["sort"]: + s.append((field_data["name"], field_data["direction"])) columns = [] rows = [] @@ -146,6 +146,9 @@ def run_query(self, query): else: cursor = db[collection].find(q, f) + if "limit" in query_data and query_data["limit"]: + cursor = cursor.limit(query_data["limit"]) + for r in cursor: for k in r: if _get_column_by_name(columns, k) is None: @@ -177,4 +180,4 @@ def run_query(self, query): return json_data, error -register(MongoDB) \ No newline at end of file +register(MongoDB) diff --git a/redash/query_runner/python.py b/redash/query_runner/python.py index 201819df06..ee0b127048 100644 --- a/redash/query_runner/python.py +++ b/redash/query_runner/python.py @@ -36,6 +36,8 @@ def custom_import(name, globals=None, locals=None, fromlist=(), level=0): raise Exception("'{0}' is not configured as a supported import module".format(name)) +def custom_get_item(obj, key): + return obj[key] def get_query_result(query_id): try: @@ -140,6 +142,7 @@ def run_query(self, query): safe_builtins["getattr"] = getattr safe_builtins["_setattr_"] = setattr safe_builtins["setattr"] = setattr + safe_builtins["_getitem_"] = custom_get_item script_locals = { "result" : { "rows" : [], "columns" : [] } } diff --git a/redash/query_runner/script.py b/redash/query_runner/script.py index e25e27fdba..e7f42f3118 100644 --- a/redash/query_runner/script.py +++ b/redash/query_runner/script.py @@ -30,7 +30,7 @@ def annotate_query(cls): def __init__(self, configuration_json): super(Script, self).__init__(configuration_json) - # Poor man's protection against running scripts from output the scripts directory + # Poor man's protection against running scripts from outside the scripts directory if self.configuration["path"].find("../") > -1: raise ValidationError("Scripts can only be run from the configured scripts directory") @@ -41,11 +41,13 @@ def run_query(self, query): query = query.strip() - script = os.path.join(self.configuration["path"], query) + script = os.path.join(self.configuration["path"], query.split(" ")[0]) if not os.path.exists(script): return None, "Script '%s' not found in script directory" % query - output = subprocess.check_output(script, shell=False) + script = os.path.join(self.configuration["path"], query) + + output = subprocess.check_output(script.split(" "), shell=False) if output is not None: output = output.strip() if output != "": @@ -62,4 +64,4 @@ def run_query(self, query): return json_data, error -register(Script) \ No newline at end of file +register(Script)