# Buggy code
def _fetch_option(cfg, ret_config, virtualname, attr_name):
    """
    Fetch a given option value from the config.

    @see :func:`get_returner_options`
    """
    # c_cfg is a dictionary returned from config.option for
    # any options configured for this returner.
    c_cfg = cfg("{0}".format(virtualname), {})

    default_cfg_key = "{0}.{1}".format(virtualname, attr_name)
    if not ret_config:
        # Using the default configuration key
        return c_cfg.get(attr_name, cfg(default_cfg_key))

    # Using ret_config to override the default configuration key
    ret_cfg = cfg("{0}.{1}".format(ret_config, virtualname), {})

    override_default_cfg_key = "{0}.{1}.{2}".format(
        ret_config,
        virtualname,
        attr_name,
    )
    override_cfg_default = cfg(override_default_cfg_key)

    # Look for the configuration item in the override location
    ret_override_cfg = ret_cfg.get(attr_name, override_cfg_default)
    if ret_override_cfg:
        return ret_override_cfg

    # if not configuration item found, fall back to the default location.
    return c_cfg.get(attr_name, cfg(default_cfg_key))


# 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 _fetch_option(cfg, ret_config, virtualname, attr_name):
    """
    Fetch a given option value from the config.

    @see :func:`get_returner_options`
    """
    # c_cfg is a dictionary returned from config.option for
    # any options configured for this returner.
    if isinstance(cfg, dict):
        c_cfg = cfg
    else:
        c_cfg = cfg("{0}".format(virtualname), {})

    default_cfg_key = "{0}.{1}".format(virtualname, attr_name)
    if not ret_config:
        # Using the default configuration key
        if isinstance(cfg, dict):
            return c_cfg.get(attr_name, cfg.get(default_cfg_key))
        else:
            return c_cfg.get(attr_name, cfg(default_cfg_key))

    # Using ret_config to override the default configuration key
    ret_cfg = cfg("{0}.{1}".format(ret_config, virtualname), {})

    override_default_cfg_key = "{0}.{1}.{2}".format(
        ret_config,
        virtualname,
        attr_name,
    )
    override_cfg_default = cfg(override_default_cfg_key)

    # Look for the configuration item in the override location
    ret_override_cfg = ret_cfg.get(attr_name, override_cfg_default)
    if ret_override_cfg:
        return ret_override_cfg

    # if not configuration item found, fall back to the default location.
    return c_cfg.get(attr_name, cfg(default_cfg_key))