You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/02/25 21:19:13 UTC

[GitHub] [superset] betodealmeida commented on a change in pull request #13346: Elizabeth/db connection analytics

betodealmeida commented on a change in pull request #13346:
URL: https://github.com/apache/superset/pull/13346#discussion_r583207350



##########
File path: superset/databases/commands/create.py
##########
@@ -69,8 +64,9 @@ def run(self) -> Model:
             security_manager.add_permission_view_menu("database_access", database.perm)
             db.session.commit()
         except DAOCreateFailedError as ex:
-            logger.exception(ex.exception)
-            raise DatabaseCreateFailedError()
+            with event_logger.log_context(action=f"db_creation_failed.{ex.exception}"):

Review comment:
       We might want to just use `log` in places like this. The main difference between `log` and `log_context` is that the former, in addition to being a context manager, logs the duration automatically, together with some dashboard/chart metadata that is irrelevant here.

##########
File path: superset/databases/commands/create.py
##########
@@ -54,10 +50,9 @@ def run(self) -> Model:
             try:
                 TestConnectionDatabaseCommand(self._actor, self._properties).run()
             except Exception:
-                db.session.rollback()
-                stats_logger.incr(
-                    f"db_connection_failed.{database.db_engine_spec.__name__}"
-                )
+                with event_logger.log_context(action=f"db_connection_failed.{database.db_engine_spec.__name__}"):
+                    db.session.rollback()

Review comment:
       This worries me a bit — if there's an error in the context manager we won't rollback the transaction.
   
   I think it would be better to just log, instead of using a context manager:
   
   ```python
   try:
       event_logger.log(action=f"db_connection_failed.{database.db_engine_spec.__name__}")
   finally:
       db.session.rollback()
   ```
   
   To ensure that `rollback` is always called.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org