You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2021/04/06 17:52:07 UTC
[superset] 01/01: use superset generic db to catch
This is an automated email from the ASF dual-hosted git repository.
hugh pushed a commit to branch hxgh/databaseerror-databaseerror-redacted-message
in repository https://gitbox.apache.org/repos/asf/superset.git
commit f64b89058dde8868eda0ec6d44f2e3905104863b
Author: hughhhh <hu...@gmail.com>
AuthorDate: Tue Apr 6 13:50:29 2021 -0400
use superset generic db to catch
---
superset/connectors/sqla/models.py | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py
index a433f03..b56a46d 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -58,7 +58,7 @@ from superset import app, db, is_feature_enabled, security_manager
from superset.connectors.base.models import BaseColumn, BaseDatasource, BaseMetric
from superset.db_engine_specs.base import TimestampExpression
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
-from superset.exceptions import QueryObjectValidationError, SupersetSecurityException
+from superset.exceptions import QueryObjectValidationError, SupersetSecurityException, SupersetGenericDBErrorException
from superset.extensions import event_logger
from superset.jinja_context import (
BaseTemplateProcessor,
@@ -645,15 +645,20 @@ class SqlaTable( # pylint: disable=too-many-public-methods,too-many-instance-at
)
# TODO(villebro): refactor to use same code that's used by
# sql_lab.py:execute_sql_statements
- with closing(engine.raw_connection()) as conn:
- cursor = conn.cursor()
- query = self.database.apply_limit_to_sql(statements[0])
- db_engine_spec.execute(cursor, query)
- result = db_engine_spec.fetch_data(cursor, limit=1)
- result_set = SupersetResultSet(
- result, cursor.description, db_engine_spec
+ try:
+ with closing(engine.raw_connection()) as conn:
+ cursor = conn.cursor()
+ query = self.database.apply_limit_to_sql(statements[0])
+ db_engine_spec.execute(cursor, query)
+ result = db_engine_spec.fetch_data(cursor, limit=1)
+ result_set = SupersetResultSet(
+ result, cursor.description, db_engine_spec
+ )
+ cols = result_set.columns
+ except Exception as exc:
+ raise SupersetGenericDBErrorException(
+ message=str(exception)
)
- cols = result_set.columns
else:
db_dialect = self.database.get_dialect()
cols = self.database.get_columns(