Repository: mindsdb/mindsdb

Issue:
Removing predictor through HTTP returns 500 
If mindsdb config have connection to DB with `publish: True`, but this DB cant be reached, then if removing predictor in Scout will return 'error 500'. That because mindsdb try to remove table related to predictor from database. That error is not critical. Probably, we need return code 200 with 'warnings' in this case, or only code 200.
Request:
```
Request URL: http://localhost:5000/api/predictors/home_days_on_market
Request Method: DELETE
Status Code: 500 INTERNAL SERVER ERROR
response
{"message": "ProgrammingError: 1698 (28000): Access denied for user 'roote'@'localhost'"}
```
error:
```
[2020-12-14 10:40:17,942] ERROR in app: Exception on /api/predictors/home_initial [DELETE]
Traceback (most recent call last):
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 233, in _open_connection
    self._cmysql.connect(**cnx_kwargs)
_mysql_connector.MySQLInterfaceError: Access denied for user 'roote'@'localhost'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/flask_restx/api.py", line 375, in wrapper
    resp = resource(*args, **kwargs)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/flask_restx/resource.py", line 44, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/mindsdb/mindsdb/api/http/namespaces/predictor.py", line 116, in delete
    ca.mindsdb_native.delete_model(name)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/mindsdb/mindsdb/interfaces/native/mindsdb.py", line 97, in delete_model
    self.dbw.unregister_predictor(name)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/mindsdb/mindsdb/interfaces/database/database.py", line 59, in unregister_predictor
    integration.unregister_predictor(name)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/mindsdb/mindsdb/integrations/mariadb/mariadb.py", line 131, in unregister_predictor
    self._query(q)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/mindsdb/mindsdb/integrations/mariadb/mariadb.py", line 42, in _query
    con = mysql.connector.connect(
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/mysql/connector/__init__.py", line 270, in connect
    return CMySQLConnection(*args, **kwargs)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 86, in __init__
    self.connect(**kwargs)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/mysql/connector/abstracts.py", line 985, in connect
    self._open_connection()
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 235, in _open_connection
    raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,
mysql.connector.errors.ProgrammingError: 1698 (28000): Access denied for user 'roote'@'localhost'
ERROR:mindsdb.api.http.initialize:Exception on /api/predictors/home_initial [DELETE]
Traceback (most recent call last):
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 233, in _open_connection
    self._cmysql.connect(**cnx_kwargs)
_mysql_connector.MySQLInterfaceError: Access denied for user 'roote'@'localhost'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/flask_restx/api.py", line 375, in wrapper
    resp = resource(*args, **kwargs)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/flask_restx/resource.py", line 44, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/mindsdb/mindsdb/api/http/namespaces/predictor.py", line 116, in delete
    ca.mindsdb_native.delete_model(name)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/mindsdb/mindsdb/interfaces/native/mindsdb.py", line 97, in delete_model
    self.dbw.unregister_predictor(name)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/mindsdb/mindsdb/interfaces/database/database.py", line 59, in unregister_predictor
    integration.unregister_predictor(name)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/mindsdb/mindsdb/integrations/mariadb/mariadb.py", line 131, in unregister_predictor
    self._query(q)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/mindsdb/mindsdb/integrations/mariadb/mariadb.py", line 42, in _query
    con = mysql.connector.connect(
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/mysql/connector/__init__.py", line 270, in connect
    return CMySQLConnection(*args, **kwargs)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 86, in __init__
    self.connect(**kwargs)
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/mysql/connector/abstracts.py", line 985, in connect
    self._open_connection()
  File "/Users/alejo/Documents/mindsdb/venv-mindsdb/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 235, in _open_connection
    raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,
mysql.connector.errors.ProgrammingError: 1698 (28000): Access denied for user 'roote'@'localhost'
```


Discussion:

Resolving patch:
diff --git a/mindsdb/interfaces/database/database.py b/mindsdb/interfaces/database/database.py
--- a/mindsdb/interfaces/database/database.py
+++ b/mindsdb/interfaces/database/database.py
@@ -4,6 +4,8 @@
 from mindsdb.integrations.mysql.mysql import MySQL
 from mindsdb.integrations.mssql.mssql import MSSQL
 
+from mindsdb.utilities.log import log as logger
+
 
 class DatabaseWrapper():
 
@@ -50,13 +52,19 @@ def register_predictors(self, model_data_arr, setup=True):
             if setup:
                 register = self._setup_integration(integration)
             if register:
-                integration.register_predictors(model_data_arr)
+                if integration.check_connection():
+                    integration.register_predictors(model_data_arr)
+                else:
+                    logger.warning(f"There is no connection to {integration.name}. predictor wouldn't be registred.")
 
             integration = [integration]
 
     def unregister_predictor(self, name):
         for integration in self._get_integrations():
-            integration.unregister_predictor(name)
+            if integration.check_connection():
+                integration.unregister_predictor(name)
+            else:
+                logger.warning(f"There is no connection to {integration.name}. predictor wouldn't be unregistred")
 
     def check_connections(self):
         connections = {}


Test patch: