villebro commented on a change in pull request #13244:
URL: https://github.com/apache/superset/pull/13244#discussion_r580286284



##########
File path: superset/db_engine_specs/base.py
##########
@@ -190,10 +205,27 @@ def get_dbapi_exception_mapping(cls) -> 
Dict[Type[Exception], Type[Exception]]:
 
         :return: A map of driver specific exception to superset custom 
exceptions
         """
-        return {}
+        dbapi_exception_names = {
+            "Error": SupersetDBAPIError,
+            "InterfaceError": SupersetDBAPIInterfaceError,
+            "DatabaseError": SupersetDBAPIDatabaseError,
+            "DataError": SupersetDBAPIDataError,
+            "OperationalError": SupersetDBAPIOperationalError,
+            "IntegrityError": SupersetDBAPIIntegrityError,
+            "InternalError": SupersetDBAPIInternalError,
+            "ProgrammingError": SupersetDBAPIProgrammingError,
+            "NotSupportedError": SupersetDBAPINotSupportedError,
+        }
+        return {
+            getattr(dbapi, exception_name): exception
+            for exception_name, exception in dbapi_exception_names.items()
+            if hasattr(dbapi, exception_name)
+        }

Review comment:
       I wonder how common it is for dbapi's to expose the exceptions in the 
main module? I quickly checked `pydruid` and `pyhive`, and they seem to export 
them in `pydruid.db.exceptions` and `pyhive.exc` respectively. We could 
potentially provide an optional path to the exception module of the specific 
spec.

##########
File path: superset/db_engine_specs/base.py
##########
@@ -941,7 +975,8 @@ def execute(cls, cursor: Any, query: str, **kwargs: Any) -> 
None:
         try:
             cursor.execute(query)
         except Exception as ex:
-            raise cls.get_dbapi_mapped_exception(ex)
+            dbapi = importlib.import_module(cursor.__module__)

Review comment:
       When forcing an error on `sqlite`, I got the following exception on this 
line:
   
![image](https://user-images.githubusercontent.com/33317356/108720682-c9855700-7529-11eb-90b9-88cd25497612.png)
   




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to