# Buggy code
def unregister_predictor(self, name):
    for integration in self._get_integrations():
        integration.unregister_predictor(name)


# Traceback (_mysql_connector.MySQLInterfaceError)
[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'

# Fixed code
def unregister_predictor(self, name):
    for integration in self._get_integrations():
        if integration.check_connection():
            integration.unregister_predictor(name)
        else:
            logger.warning(
                f"There is no connection to {integration.name}. predictor wouldn't be unregistred"
            )