'Hack sorting double chained task lists by task_id to avoid hitting
max_depth on deepcopy operations.'

def __deepcopy__(self, memo):

    sys.setrecursionlimit(5000)
    cls = self.__class__
    result = cls.__new__(cls)
    memo[id(self)] = result
    for (k, v) in list(self.__dict__.items()):
        if (k not in (u'user_defined_macros', u'user_defined_filters', u'params')):
            setattr(result, k, copy.deepcopy(v, memo))
    result.params = self.params
    if hasattr(self, u'user_defined_macros'):
        result.user_defined_macros = self.user_defined_macros
    if hasattr(self, u'user_defined_filters'):
        result.user_defined_filters = self.user_defined_filters
    return result
