# Buggy code
def grant_revoke(
    grant,
    database,
    user,
    host="localhost",
    grant_option=False,
    escape=True,
    **connection_args,
):
    """
    Removes a grant from the MySQL server.

    CLI Example:

    .. code-block:: bash

        salt '*' mysql.grant_revoke 'SELECT,INSERT,UPDATE' 'database.*' 'frank' 'localhost'
    """
    # todo: validate grant
    dbc = _connect(**connection_args)
    if dbc is None:
        return False
    cur = dbc.cursor()

    if grant_option:
        grant += ", GRANT OPTION"
    qry = "REVOKE {0} ON {1} FROM {2!r}@{3!r};".format(grant, database, user, host)
    log.debug("Query: {0}".format(qry))
    try:
        cur.execute(qry)
    except MySQLdb.OperationalError as exc:
        err = "MySQL Error {0}: {1}".format(*exc)
        __context__["mysql.error"] = err
        log.error(err)
        return False

    if not grant_exists(
        grant, database, user, host, grant_option, escape, **connection_args
    ):
        log.info(
            "Grant {0!r} on {1!r} for user {2!r} has been revoked".format(
                grant, database, user
            )
        )
        return True

    log.info(
        "Grant {0!r} on {1!r} for user {2!r} has NOT been revoked".format(
            grant, database, user
        )
    )
    return False


# Traceback (AttributeError)
[ERROR   ] Error in function _master_opts:
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/salt/master.py", line 1444, in run_func
ret = getattr(self, func)(load)
File "/usr/lib/pymodules/python2.7/salt/master.py", line 891, in _master_opts
envs = self._file_envs()
File "/usr/lib/pymodules/python2.7/salt/fileserver/__init__.py", line 153, in envs
ret.update(self.servers[fstr]())
File "/usr/lib/pymodules/python2.7/salt/fileserver/hgfs.py", line 176, in envs
tags = repo.get_tags()
AttributeError: 'hgclient' object has no attribute 'get_tags'

# Fixed code
def grant_revoke(
    grant,
    database,
    user,
    host="localhost",
    grant_option=False,
    escape=True,
    **connection_args,
):
    """
    Removes a grant from the MySQL server.

    CLI Example:

    .. code-block:: bash

        salt '*' mysql.grant_revoke 'SELECT,INSERT,UPDATE' 'database.*' 'frank' 'localhost'
    """
    # todo: validate grant
    dbc = _connect(**connection_args)
    if dbc is None:
        return False
    cur = dbc.cursor()

    if salt.utils.is_true(grant_option):
        grant += ", GRANT OPTION"
    qry = "REVOKE {0} ON {1} FROM {2!r}@{3!r};".format(grant, database, user, host)
    log.debug("Query: {0}".format(qry))
    try:
        cur.execute(qry)
    except MySQLdb.OperationalError as exc:
        err = "MySQL Error {0}: {1}".format(*exc)
        __context__["mysql.error"] = err
        log.error(err)
        return False

    if not grant_exists(
        grant, database, user, host, grant_option, escape, **connection_args
    ):
        log.info(
            "Grant {0!r} on {1!r} for user {2!r} has been revoked".format(
                grant, database, user
            )
        )
        return True

    log.info(
        "Grant {0!r} on {1!r} for user {2!r} has NOT been revoked".format(
            grant, database, user
        )
    )
    return False