# Buggy code
def returner(ret):
    """
    Return data to a mysql server
    """
    with _get_serv(ret, commit=True) as cur:
        sql = """INSERT INTO `salt_returns`
                (`fun`, `jid`, `return`, `id`, `success`, `full_ret` )
                VALUES (%s, %s, %s, %s, %s, %s)"""

        cur.execute(
            sql,
            (
                ret["fun"],
                ret["jid"],
                json.dumps(ret["return"]),
                ret["id"],
                ret["success"],
                json.dumps(ret),
            ),
        )


# Traceback (TypeError)
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
TypeError: 'dict' object is not callable
Traceback (most recent call last):
File "/usr/bin/salt", line 10, in <module>
salt_main()
File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 351, in salt_main
client.run()
File "/usr/lib/python2.7/dist-packages/salt/cli/salt.py", line 191, in run
for full_ret in cmd_func(**kwargs):
File "/usr/lib/python2.7/dist-packages/salt/client/__init__.py", line 594, in cmd_cli
**kwargs):
File "/usr/lib/python2.7/dist-packages/salt/client/__init__.py", line 1235, in get_cli_event_returns
expect_minions=(verbose or show_timeout)
File "/usr/lib/python2.7/dist-packages/salt/client/__init__.py", line 862, in get_iter_returns
if self.returners['{0}.get_load'.format(self.opts['master_job_cache'])](jid) == {}:
File "/usr/lib/python2.7/dist-packages/salt/returners/mysql.py", line 229, in get_load
with _get_serv(ret=None, commit=True) as cur:
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/usr/lib/python2.7/dist-packages/salt/returners/mysql.py", line 157, in _get_serv
_options = _get_options(ret)
File "/usr/lib/python2.7/dist-packages/salt/returners/mysql.py", line 145, in _get_options
defaults=defaults)
File "/usr/lib/python2.7/dist-packages/salt/returners/__init__.py", line 85, in get_returner_options
attrs,
File "/usr/lib/python2.7/dist-packages/salt/returners/__init__.py", line 164, in _options_browser
value = _fetch_option(cfg, ret_config, virtualname, options[option])
File "/usr/lib/python2.7/dist-packages/salt/returners/__init__.py", line 125, in _fetch_option
c_cfg = cfg('{0}'.format(virtualname), {})
TypeError: 'dict' object is not callable
Traceback (most recent call last):
File "/usr/bin/salt", line 10, in <module>
salt_main()
File "/usr/lib/python2.7/dist-packages/salt/scripts.py", line 351, in salt_main
client.run()
File "/usr/lib/python2.7/dist-packages/salt/cli/salt.py", line 191, in run
for full_ret in cmd_func(**kwargs):
File "/usr/lib/python2.7/dist-packages/salt/client/__init__.py", line 594, in cmd_cli
**kwargs):
File "/usr/lib/python2.7/dist-packages/salt/client/__init__.py", line 1235, in get_cli_event_returns
expect_minions=(verbose or show_timeout)
File "/usr/lib/python2.7/dist-packages/salt/client/__init__.py", line 862, in get_iter_returns
if self.returners['{0}.get_load'.format(self.opts['master_job_cache'])](jid) == {}:
File "/usr/lib/python2.7/dist-packages/salt/returners/mysql.py", line 229, in get_load
with _get_serv(ret=None, commit=True) as cur:
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/usr/lib/python2.7/dist-packages/salt/returners/mysql.py", line 157, in _get_serv
_options = _get_options(ret)
File "/usr/lib/python2.7/dist-packages/salt/returners/mysql.py", line 145, in _get_options
defaults=defaults)
File "/usr/lib/python2.7/dist-packages/salt/returners/__init__.py", line 85, in get_returner_options
attrs,
File "/usr/lib/python2.7/dist-packages/salt/returners/__init__.py", line 164, in _options_browser
value = _fetch_option(cfg, ret_config, virtualname, options[option])
File "/usr/lib/python2.7/dist-packages/salt/returners/__init__.py", line 125, in _fetch_option
c_cfg = cfg('{0}'.format(virtualname), {})
TypeError: 'dict' object is not callable

# Fixed code
def returner(ret):
    """
    Return data to a mysql server
    """
    try:
        with _get_serv(ret, commit=True) as cur:
            sql = """INSERT INTO `salt_returns`
                    (`fun`, `jid`, `return`, `id`, `success`, `full_ret` )
                    VALUES (%s, %s, %s, %s, %s, %s)"""

            cur.execute(
                sql,
                (
                    ret["fun"],
                    ret["jid"],
                    json.dumps(ret["return"]),
                    ret["id"],
                    ret["success"],
                    json.dumps(ret),
                ),
            )
    except salt.exceptions.SaltMasterError:
        log.critical(
            "Could not store return with MySQL returner. MySQL server unavailable."
        )