Skip to content

Commit

Permalink
Improve visibility of error message during schema retrieval (getredas…
Browse files Browse the repository at this point in the history
…h#5879)

* handle query execution error in one place. increase ability to debug issues with schema retrieval

* split message and details for error reporting

Co-authored-by: Dmitriy Apollonin <[email protected]>
  • Loading branch information
apollonin and Dmitriy Apollonin authored Jan 5, 2023
1 parent 3280991 commit 5cf13af
Show file tree
Hide file tree
Showing 22 changed files with 31 additions and 24 deletions.
7 changes: 7 additions & 0 deletions redash/query_runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ def fetch_columns(self, columns):
def get_schema(self, get_stats=False):
raise NotSupported()

def _handle_run_query_error(self, error):
if error is None:
return

logger.error(error)
raise Exception(f"Error during query execution. Reason: {error}")

def _run_query_internal(self, query):
results, error = self.run_query(query, None)

Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/athena.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def get_schema(self, get_stats=False):

results, error = self.run_query(query, None)
if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results = json_loads(results)
for row in results["rows"]:
Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/azure_kusto.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def get_schema(self, get_stats=False):
results, error = self.run_query(query, None)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results = json_loads(results)

Expand Down
4 changes: 2 additions & 2 deletions redash/query_runner/big_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def get_schema(self, get_stats=False):
query = '\nUNION ALL\n'.join(queries)
results, error = self.run_query(query, None)
if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results = json_loads(results)
for row in results["rows"]:
Expand Down Expand Up @@ -341,7 +341,7 @@ def run_query(self, query, user):
json_data = json_dumps(data, ignore_nan=True)
except apiclient.errors.HttpError as e:
json_data = None
if e.resp.status == 400:
if e.resp.status in [400, 404]:
error = json_loads(e.content)["error"]["message"]
else:
error = e.content
Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _get_tables(self, schema):
results, error = self.run_query(query, None)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results = json_loads(results)

Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def get_databases(self):
results, error = self.run_query(query, None)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results = json_loads(results)

Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/db2.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _get_definitions(self, schema, query):
results, error = self.run_query(query, None)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results = json_loads(results)

Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/drill.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def get_schema(self, get_stats=False):
results, error = self.run_query(query, None)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results = json_loads(results)

Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/druid.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_schema(self, get_stats=False):
results, error = self.run_query(query, None)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

schema = {}
results = json_loads(results)
Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/firebolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_schema(self, get_stats=False):
results, error = self.run_query(query, None)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

schema = {}
results = json_loads(results)
Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _get_tables(self, schema):
results, error = self.run_query(query, None)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results = json_loads(results)

Expand Down
4 changes: 2 additions & 2 deletions redash/query_runner/mssql_odbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def name(cls):
@classmethod
def type(cls):
return "mssql_odbc"

@property
def supports_auto_limit(self):
return False
Expand All @@ -86,7 +86,7 @@ def _get_tables(self, schema):
results, error = self.run_query(query, None)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results = json_loads(results)

Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _get_tables(self, schema):
results, error = self.run_query(query, None)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results = json_loads(results)

Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _get_tables(self, schema):
results, error = self.run_query(query, None)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results = json_loads(results)

Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def _get_definitions(self, schema, query):
results, error = self.run_query(query, None)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results = json_loads(results)

Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/phoenix.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_schema(self, get_stats=False):
results, error = self.run_query(query, None)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results = json_loads(results)

Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_schema(self, get_stats=False):
results, error = self.run_query(query, None)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results = json_loads(results)

Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def get_schema(self, get_stats=False):
results, error = self._run_query_without_warehouse(query)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

schema = {}
for row in results["rows"]:
Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _get_tables(self, schema):
schema[table_name] = {"name": table_name, "columns": []}
results_table, error = self.run_query(query_columns % (table_name,), None)
if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results_table = json_loads(results_table)
for row_column in results_table["rows"]:
Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_schema(self, get_stats=False):
results, error = self.run_query(query, None)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results = json_loads(results)
schema = {}
Expand Down
2 changes: 1 addition & 1 deletion redash/query_runner/vertica.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _get_tables(self, schema):
results, error = self.run_query(query, None)

if error is not None:
raise Exception("Failed getting schema.")
self._handle_run_query_error(error)

results = json_loads(results)

Expand Down
4 changes: 2 additions & 2 deletions redash/tasks/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def get_schema(data_source_id, refresh):
"message": "Data source type does not support retrieving schema",
}
}
except Exception:
return {"error": {"code": 2, "message": "Error retrieving schema."}}
except Exception as e:
return {"error": {"code": 2, "message": "Error retrieving schema", "details": str(e)}}


def sync_user_details():
Expand Down

0 comments on commit 5cf13af

Please sign in to comment.