From eb77e7ff232e47fbd4afc2140f7cd5e1f6390c72 Mon Sep 17 00:00:00 2001 From: Arash Date: Tue, 31 Aug 2021 11:50:28 -0400 Subject: [PATCH 1/2] adding logging to validation --- .../src/views/CRUD/data/database/DatabaseModal/index.tsx | 6 +++--- superset/databases/commands/test_connection.py | 4 ++++ superset/databases/commands/validate.py | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx index 55bceb7369570..0a03df4d2171c 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx @@ -908,14 +908,14 @@ const DatabaseModal: FunctionComponent = ({ /> ); } - - const message: Array = Object.values(dbErrors); + const message: Array | null = + typeof dbErrors === 'object' ? Object.values(dbErrors) : null; return ( antDErrorAlertStyles(theme)} message="Database Creation Error" - description={message[0]} + description={message?.[0] || dbErrors} /> ); }; diff --git a/superset/databases/commands/test_connection.py b/superset/databases/commands/test_connection.py index 7b2f4da687c66..2d44bed940a0b 100644 --- a/superset/databases/commands/test_connection.py +++ b/superset/databases/commands/test_connection.py @@ -72,6 +72,10 @@ def run(self) -> None: database.db_engine_spec.mutate_db_for_connection_test(database) username = self._actor.username if self._actor is not None else None engine = database.get_sqla_engine(user_name=username) + event_logger.log_with_context( + action="test_connection_attempt", + engine=database.db_engine_spec.__name__, + ) with closing(engine.raw_connection()) as conn: try: alive = engine.dialect.do_ping(conn) diff --git a/superset/databases/commands/validate.py b/superset/databases/commands/validate.py index 27633d2c15c5e..e2dcc581d7fbf 100644 --- a/superset/databases/commands/validate.py +++ b/superset/databases/commands/validate.py @@ -33,6 +33,7 @@ from superset.db_engine_specs import get_engine_specs from superset.db_engine_specs.base import BasicParametersMixin from superset.errors import ErrorLevel, SupersetError, SupersetErrorType +from superset.extensions import event_logger from superset.models.core import Database BYPASS_VALIDATION_ENGINES = {"bigquery"} @@ -89,6 +90,7 @@ def run(self) -> None: self._properties.get("parameters", {}) ) if errors: + event_logger.log_with_context(action="validation_error", engine=engine) raise InvalidParametersError(errors) serialized_encrypted_extra = self._properties.get("encrypted_extra", "{}") From 9f59b4f8f682f6a55b83d8422700edd3e460347e Mon Sep 17 00:00:00 2001 From: AAfghahi <48933336+AAfghahi@users.noreply.github.com> Date: Tue, 31 Aug 2021 16:18:03 -0400 Subject: [PATCH 2/2] Update superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx Co-authored-by: Beto Dealmeida --- .../src/views/CRUD/data/database/DatabaseModal/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx index 0a03df4d2171c..82db9e7f17da6 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx @@ -908,8 +908,8 @@ const DatabaseModal: FunctionComponent = ({ /> ); } - const message: Array | null = - typeof dbErrors === 'object' ? Object.values(dbErrors) : null; + const message: Array = + typeof dbErrors === 'object' ? Object.values(dbErrors) : []; return (