diff --git a/src/caosdb/common/models.py b/src/caosdb/common/models.py index 16001ed8847ec853c21851e101aea54f7377d632..00522ee614cccc79c9c56b469d00b635059260b6 100644 --- a/src/caosdb/common/models.py +++ b/src/caosdb/common/models.py @@ -2880,8 +2880,10 @@ class Container(list): """ item_id = set() is_parent = set() - has_references = set() + is_property = set() + is_being_referenced = set() dependent_parents = set() + dependent_properties = set() dependent_references = set() dependencies = set() @@ -2896,26 +2898,31 @@ class Container(list): # add only if it is a reference, not a property if isinstance(references.value, int): - has_references.add(references.value) + is_being_referenced.add(references.value) elif is_list_datatype(references.datatype): for list_item in references.value: if isinstance(list_item, int): - has_references.add(list_item) + is_being_referenced.add(list_item) else: - has_references.add(list_item.id) + is_being_referenced.add(list_item.id) else: try: - has_references.add(references.value.id) + is_being_referenced.add(references.value.id) except: pass + if hasattr(references, 'id'): + is_property.add(references.id) + dependent_parents = item_id.intersection(is_parent) - dependent_references = item_id.intersection(has_references) + dependent_properties = item_id.intersection(is_property) + dependent_references = item_id.intersection(is_being_referenced) dependencies = dependent_parents.union(dependent_references) + dependencies = dependencies.union(dependent_properties) return dependencies - def delete(self, raise_exception_on_error=True, flags=None): + def delete(self, raise_exception_on_error=True, flags=None, chunk_size=100): """Delete all entities in this container. Entities are identified via their id if present and via their @@ -2926,7 +2933,6 @@ class Container(list): this happens, none of them will be deleted. It occurs an error instead. """ - chunk_size = 100 item_count = len(self) # Split Container in 'chunk_size'-sized containers (if necessary) to avoid error 414 Request-URI Too Long diff --git a/unittests/test_container.py b/unittests/test_container.py index a2df1558478ccbd6f9b55f24f66afce255ec6e13..2e8dfa2a9b4538f854d79ad08f4500c11bf68945 100644 --- a/unittests/test_container.py +++ b/unittests/test_container.py @@ -88,6 +88,9 @@ def test_container_dependencies_for_deletion(): property_which_is_not_a_record = db.Property( "Normal Property", datatype=db.DOUBLE, value=1006) property_which_is_not_a_record.id = 1006 + property_which_shall_be_deleted = db.Property( + "Normal Property 2", datatype=db.DOUBLE, value=1006) + property_which_shall_be_deleted .id = 1007 record_without_dependencies = db.Record().add_parent(not_included_rt) record_without_dependencies.id = 2003 @@ -106,18 +109,22 @@ def test_container_dependencies_for_deletion(): record_with_property_which_is_not_a_record.id = 2006 record_with_property_which_is_not_a_record.add_property( property_which_is_not_a_record) + record_with_property_which_is_not_a_record.add_property( + property_which_shall_be_deleted) container = db.Container() container.extend([ rt, rt_record_with_parent, # 1005, dependency record_without_dependencies, + property_which_shall_be_deleted, # 1007, dependency record_referenced, # 2002, dependency record_with_dependencies, record_with_parent, record_with_property_which_is_not_a_record ]) - assert db.Container()._test_dependencies_in_container(container) == {2002, 1005} + assert (db.Container()._test_dependencies_in_container(container) + == {2002, 1005, 1007}) def test_container_dependencies_for_deletion_with_lists():