# Buggy code
def verylong_encoder(obj):
    if isinstance(obj, dict):
        for key, value in six.iteritems(obj.copy()):
            obj[key] = verylong_encoder(value)
        return dict(obj)
    elif isinstance(obj, (list, tuple)):
        obj = list(obj)
        for idx, entry in enumerate(obj):
            obj[idx] = verylong_encoder(entry)
        return obj
    # This is a spurious lint failure as we are gating this check
    # behind a check for six.PY2.
    if six.PY2 and isinstance(obj, long) and long > pow(2, 64):  # pylint: disable=incompatible-py3-code
        return six.text_type(obj)
    elif six.PY3 and isinstance(obj, int) and int > pow(2, 64):
        return six.text_type(obj)
    else:
        return obj


# Traceback (SaltClientError)
2018-02-26 18:02:15,266 [salt.minion      :204 ][WARNING ][16492] Master ip address changed from 10.1.51.25 to 10.1.51.24
2018-02-26 18:02:15,616 [salt.minion      :433 ][ERROR   ][16492] Exception unsupported operand type(s) for -: 'str' and 'datetime.datetime' occurred in scheduled job
2018-02-26 18:02:16,613 [salt.minion      :433 ][ERROR   ][16492] Exception unsupported operand type(s) for -: 'str' and 'datetime.datetime' occurred in scheduled job
2018-02-26 18:02:17,611 [salt.minion      :433 ][ERROR   ][16492] Exception unsupported operand type(s) for -: 'str' and 'datetime.datetime' occurred in scheduled job
2018-02-26 18:02:18,611 [salt.minion      :433 ][ERROR   ][16492] Exception unsupported operand type(s) for -: 'str' and 'datetime.datetime' occurred in scheduled job
2018-02-26 18:02:19,611 [salt.minion      :433 ][ERROR   ][16492] Exception unsupported operand type(s) for -: 'str' and 'datetime.datetime' occurred in scheduled job
2018-02-26 18:02:20,288 [salt.minion      :204 ][WARNING ][16492] Master ip address changed from 10.1.51.24 to 10.1.51.25
2018-02-26 18:02:20,611 [salt.minion      :433 ][ERROR   ][16492] Exception unsupported operand type(s) for -: 'str' and 'datetime.datetime' occurred in scheduled job
2018-02-26 18:02:21,611 [salt.minion      :433 ][ERROR   ][16492] Exception unsupported operand type(s) for -: 'str' and 'datetime.datetime' occurred in scheduled job
2018-02-26 18:02:22,610 [salt.minion      :433 ][ERROR   ][16492] Exception unsupported operand type(s) for -: 'str' and 'datetime.datetime' occurred in scheduled job
2018-02-26 18:02:23,619 [salt.minion      :433 ][ERROR   ][16492] Exception unsupported operand type(s) for -: 'str' and 'datetime.datetime' occurred in scheduled job
2018-02-26 18:02:24,620 [salt.minion      :433 ][ERROR   ][16492] Exception unsupported operand type(s) for -: 'str' and 'datetime.datetime' occurred in scheduled job
2018-02-26 18:02:25,300 [salt.minion      :644 ][ERROR   ][16492] No master could be reached or all masters denied the minion's connection attempt.
2018-02-26 18:02:25,301 [salt.scripts     :146 ][WARNING ][16492] Fatal functionality error caught by minion handler:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 144, in minion_process
minion.start()
File "/usr/lib/python2.7/site-packages/salt/cli/daemons.py", line 350, in start
raise SaltClientError('Minion could not connect to Master')
SaltClientError: Minion could not connect to Master
2018-02-26 18:02:25,301 [salt.scripts     :147 ][WARNING ][16492] ** Restarting minion **

# Fixed code
def verylong_encoder(obj):
    if isinstance(obj, dict):
        for key, value in six.iteritems(obj.copy()):
            obj[key] = verylong_encoder(value)
        return dict(obj)
    elif isinstance(obj, (list, tuple)):
        obj = list(obj)
        for idx, entry in enumerate(obj):
            obj[idx] = verylong_encoder(entry)
        return obj
    # A value of an Integer object is limited from -(2^63) upto (2^64)-1 by MessagePack
    # spec. Here we care only of JIDs that are positive integers.
    if isinstance(obj, six.integer_types) and obj >= pow(2, 64):
        return six.text_type(obj)
    else:
        return obj