# Buggy code
def absent(name, **connection_args):
    """
    Ensure that the named database is absent

    name
        The name of the database to remove
    """
    ret = {"name": name, "changes": {}, "result": True, "comment": ""}

    # check if db exists and remove it
    if __salt__["mysql.db_exists"](name, **connection_args):
        if __opts__["test"]:
            ret["result"] = None
            ret["comment"] = "Database {0} is present and needs to be removed".format(
                name
            )
            return ret
        if __salt__["mysql.db_remove"](name, **connection_args):
            ret["comment"] = "Database {0} has been removed".format(name)
            ret["changes"][name] = "Absent"
            return ret
        else:
            err = _get_mysql_error()
            if err is not None:
                ret["comment"] = "Unable to remove database {0} ({1})".format(name, err)
                ret["result"] = False
                return ret
    else:
        err = _get_mysql_error()
        if err is not None:
            ret["comment"] = err
            ret["result"] = False
            return ret

    # fallback
    ret["comment"] = ("Database {0} is not present, so it cannot be removed").format(
        name
    )
    return ret


# Traceback (_mysql_exceptions.ProgrammingError)
2019-07-11 09:06:57,236 [salt.state       :1838][INFO    ][11082] Executing state mysql_database.present for [cebeluya]
2019-07-11 09:06:57,237 [salt.loaded.int.module.mysql:608 ][DEBUG   ][11082] Doing query: SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME=%(dbname)s; args: {'dbname': 'cebeluya'}
2019-07-11 09:06:57,238 [salt.loaded.int.states.mysql_database:60  ][DEBUG   ][11082] character set differes from utf8mb4 : utf8mb4
2019-07-11 09:06:57,239 [salt.loaded.int.module.mysql:608 ][DEBUG   ][11082] Doing query: SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME=%(dbname)s; args: {'dbname': 'cebeluya'}
2019-07-11 09:06:57,239 [salt.loaded.int.module.mysql:605 ][DEBUG   ][11082] Doing query: ALTER DATABASE `cebeluya` CHARACTER SET utf8mb4 COLLATE b'utf8mb4_general_ci';
2019-07-11 09:06:57,239 [salt.state       :1925][DEBUG   ][11082] An exception occurred in this state: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'b'utf8mb4_general_ci'' at line 1")
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/salt/state.py", line 1919, in call
**cdata['kwargs'])
File "/usr/lib/python3/dist-packages/salt/loader.py", line 1918, in wrapper
return f(*args, **kwargs)
File "/usr/lib/python3/dist-packages/salt/states/mysql_database.py", line 72, in present
**connection_args)
File "/usr/lib/python3/dist-packages/salt/modules/mysql.py", line 1021, in alter_db
_execute(cur, qry, args)
File "/usr/lib/python3/dist-packages/salt/modules/mysql.py", line 606, in _execute
return cur.execute(qry)
File "/usr/lib/python3/dist-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python3/dist-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/usr/lib/python3/dist-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/usr/lib/python3/dist-packages/MySQLdb/cursors.py", line 411, in _query
rowcount = self._do_query(q)
File "/usr/lib/python3/dist-packages/MySQLdb/cursors.py", line 374, in _do_query
db.query(q)
File "/usr/lib/python3/dist-packages/MySQLdb/connections.py", line 292, in query
_mysql.connection.query(self, query)
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'b'utf8mb4_general_ci'' at line 1")

# Fixed code
def absent(name, **connection_args):
    """
    Ensure that the named database is absent

    name
        The name of the database to remove
    """
    ret = {"name": name, "changes": {}, "result": True, "comment": ""}

    # check if db exists and remove it
    if __salt__["mysql.db_exists"](name, **connection_args):
        if __opts__.get("test", False):
            ret["result"] = None
            ret["comment"] = "Database {} is present and needs to be removed".format(
                name
            )
            return ret
        if __salt__["mysql.db_remove"](name, **connection_args):
            ret["comment"] = "Database {} has been removed".format(name)
            ret["changes"][name] = "Absent"
            return ret
        else:
            err = _get_mysql_error()
            if err is not None:
                ret["comment"] = "Unable to remove database {} ({})".format(name, err)
                ret["result"] = False
                return ret
    else:
        err = _get_mysql_error()
        if err is not None:
            ret["comment"] = err
            ret["result"] = False
            return ret

    # fallback
    ret["comment"] = ("Database {} is not present, so it cannot be removed").format(
        name
    )
    return ret