diff --git a/redash/cli/data_sources.py b/redash/cli/data_sources.py index 0757a191be..b6a311d5cf 100644 --- a/redash/cli/data_sources.py +++ b/redash/cli/data_sources.py @@ -83,7 +83,7 @@ def get_data_source_version(name, organization='default'): name, data_source.id) try: info = data_source.query_runner.get_data_source_version() - except Exception, e: + except Exception as e: print "Failure: {}".format(e) exit(1) else: diff --git a/redash/query_runner/__init__.py b/redash/query_runner/__init__.py index ec9338367f..c3658a3d26 100644 --- a/redash/query_runner/__init__.py +++ b/redash/query_runner/__init__.py @@ -77,16 +77,21 @@ def get_data_source_version(self): if self.data_source_version_query is None: raise NotImplementedError data, error = self.run_query(self.data_source_version_query, None) - version = json.loads(data)['rows'][0]['version'] - if(self.data_source_version_post_process == "split by space take second"): + + if error is not None: + raise Exception(error) + + try: + version = json.loads(data)['rows'][0]['version'] + except KeyError as e: + raise Exception(e) + + if self.data_source_version_post_process == "split by space take second": version = version.split(" ")[1] - elif(self.data_source_version_post_process == "split by space take last"): + elif self.data_source_version_post_process == "split by space take last": version = version.split(" ")[-1] - elif(self.data_source_version_post_process == "none"): + elif self.data_source_version_post_process == "none": version = version - - if error is not None: - raise Exception(error) return version