Ejemplo n.º 1
0
def delete_all(session, entities):
    """
    Delete a list of entities.

    :param session:
    :type session: Session
    :param entities:
    :type entities: list

    :returns: A list of deleted objects.
    :rtype: list
    """
    for ent in entities:
        if hasattr(ent, "location"):
            deleted = []
            try:
                session.delete(ent)
                deleted.append(ent)
            except RuntimeError as e:
                # TODO logging
                pass
Ejemplo n.º 2
0
            todo.remove(local_native)  # remove processed object

        todo_ids = [id(obj) for obj in todo]
        for field_name in local_model.child_fields:
            if hasattr(local_native, field_name) and \
                    hasattr(remote_native, field_name):

                # set difference between the actual remote and local children
                # references determines the list of children to delete
                local_children = getattr(local_native, field_name, [])
                remote_children = getattr(remote_native, field_name, [])
                to_clean += compare_objs(local_children, remote_children)

                # skip empty lazy-loaded proxy relations
                if not (hasattr(local_children, '_is_loaded') and
                            not getattr(local_children, '_is_loaded')) and \
                        (local_children is not None):
                    for obj in local_children:
                        loc = getattr(obj, 'location', None)
                        if not (loc is not None and loc in processed) and \
                                not id(obj) in todo_ids:
                            todo.append(obj)

    # cleaning removed objects
    for entity in to_clean:
        try:
            session.delete(entity)
        except Exception, e:
            exceptions.append(e)

    return exceptions