首页 > 解决方案 > Django Celery递归错误与tasks.py,不与views.py

问题描述

我创建了一个递归函数来获取某个对象的所有子对象。

    def get_all_children(self):
    children = [self]
    try:
        child_list = self.children.all()
    except AttributeError:
        return children
    for child in child_list:
        children.extend(child.get_all_children())
    return children

当我在 views.py 文件中调用此函数时,它工作正常。但它给了我一个 RecursionError: maximum recursion depth exceeded in contrast when I call the same function in my celery tasks.py 文件

标签: djangorecursioncelery

解决方案


推荐阅读