diff --git a/src/caosadvancedtools/cfood.py b/src/caosadvancedtools/cfood.py index 58cae5d0e65750a3e47618b5b228fabc007a097a..a6e442941a4d5c91367f866f56ec5d0ffa166ae6 100644 --- a/src/caosadvancedtools/cfood.py +++ b/src/caosadvancedtools/cfood.py @@ -201,13 +201,14 @@ def assure_object_is_in_list(obj, containing_object, property_name, to_be_updated.append(containing_object) -def assure_has_parent(entity, parent, to_be_updated, verbose=True): +def assure_has_parent(entity, parent, to_be_updated=None, verbose=True): """ Checks whether `entity` has a parent with name `parent`. - If this is the case this function returns. Otherwise the entity is assigned - a new parent and is added to the supplied list to_be_updated in order to - indicate, that the entity `entity` should be updated. + If this is the case this function ends. Otherwise the entity is assigned + a new parent. The list to_be_updated is supplied, the entity is added to + the list in order to indicate, that the entity `entity` should be updated. + Otherwise it is directly updated """ parents = entity.get_parents() contained = False @@ -227,7 +228,11 @@ def assure_has_parent(entity, parent, to_be_updated, verbose=True): if verbose: print("Adding parent {} to entity {}".format(parent, entity.id)) entity.add_parent(parent) - to_be_updated.append(entity) + + if to_be_updated is None: + entity.update(unique=False) + else: + to_be_updated.append(entity) def insert_id_based_on_name(entity):