def clear_parent_children_cache(instance):
    """
    Clears the children_cache of the instance-parent if the instance has
    a parent and the parent is not the instance itself (i.e. pointing to
    itself). The latter will cause an unlimited recursion.
    """
    parent = instance.parent
    if parent and parent != instance:
        if parent.children_cache:
            parent.children_cache = ''
            parent.save()
