# Buggy code
def __singleton_init__(
    self, opts, functions, returners=None, intervals=None, cleanup=None
):
    self.opts = opts
    self.functions = functions
    if isinstance(intervals, dict):
        self.intervals = intervals
    else:
        self.intervals = {}
    if hasattr(returners, "__getitem__"):
        self.returners = returners
    else:
        self.returners = returners.loader.gen_functions()
    self.time_offset = self.functions.get("timezone.get_offset", lambda: "0000")()
    self.schedule_returner = self.option("schedule_returner")
    # Keep track of the lowest loop interval needed in this variable
    self.loop_interval = six.MAXSIZE
    clean_proc_dir(opts)
    if cleanup:
        for prefix in cleanup:
            self.delete_job_prefix(prefix)


# Traceback (KeyError)
[INFO    ] Running scheduled job: napalm_keepalive
[DEBUG   ] schedule: This job was scheduled with jid_include, adding to cache (jid_include defaults to True)
[DEBUG   ] schedule: This job was scheduled with a max number of 2
[DEBUG   ] schedule.handle_func: adding this job to the jobcache with data {'fun_args': [], 'jid': '20170302001945879004', 'schedule': 'napalm_keepalive', 'pid': 18056, 'fun': 'napalm_proxy.reconnect', 'id': 'device1'}
[DEBUG   ] LazyLoaded napalm_proxy.reconnect
[ERROR   ] Unhandled exception running napalm_proxy.reconnect
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/utils/schedule.py", line 836, in handle_func
ret['return'] = self.functions[func](*args, **kwargs)
File "/var/cache/salt/minion/extmods/modules/napalm_proxy.py", line 101, in reconnect
is_alive = alive()
File "/var/cache/salt/minion/extmods/modules/napalm_proxy.py", line 80, in alive
return __proxy__['napalm.call'](
File "/usr/lib/python2.7/dist-packages/salt/utils/context.py", line 203, in __getitem__
return self._dict()[key]
KeyError: 'napalm.call'
[DEBUG   ] SaltEvent PUB socket URI: /var/run/salt/minion/minion_event_18faa0dd7a_pub.ipc
[DEBUG   ] SaltEvent PULL socket URI: /var/run/salt/minion/minion_event_18faa0dd7a_pull.ipc
[DEBUG   ] Initializing new IPCClient for path: /var/run/salt/minion/minion_event_18faa0dd7a_pull.ipc
[DEBUG   ] Sending event: tag = __schedule_return; data = {'fun_args': [], 'jid': 'req', 'return': 'Unhandled exception running napalm_proxy.reconnect', 'retcode': 254, 'success': False, 'schedule': 'napalm_keepalive', 'cmd': '_return', 'pid': 18056, '_stamp': '2017-03-02T00:19:45.881385', 'fun': 'napalm_proxy.reconnect', 'id': 'device1'}
[DEBUG   ] schedule.handle_func: Removing /var/cache/salt/proxy/device1/proc/20170302001945879004

# Fixed code
def __singleton_init__(
    self, opts, functions, returners=None, intervals=None, cleanup=None, proxy=None
):
    self.opts = opts
    self.proxy = proxy
    self.functions = functions
    if isinstance(intervals, dict):
        self.intervals = intervals
    else:
        self.intervals = {}
    if hasattr(returners, "__getitem__"):
        self.returners = returners
    else:
        self.returners = returners.loader.gen_functions()
    self.time_offset = self.functions.get("timezone.get_offset", lambda: "0000")()
    self.schedule_returner = self.option("schedule_returner")
    # Keep track of the lowest loop interval needed in this variable
    self.loop_interval = six.MAXSIZE
    clean_proc_dir(opts)
    if cleanup:
        for prefix in cleanup:
            self.delete_job_prefix(prefix)