Fix #3974. Bug where orphaned histories would be left in API remove operations.

This commit is contained in:
Dion Moult
2023-11-28 10:45:49 +11:00
parent 58414777be
commit 6e932ec2fb
50 changed files with 314 additions and 86 deletions
@@ -109,7 +109,10 @@ class Usecase:
decomposes.RelatedObjects = related_objects
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": decomposes})
else:
history = decomposes.OwnerHistory
self.file.remove(decomposes)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
if is_decomposed_by:
related_objects = set(is_decomposed_by.RelatedObjects)
@@ -18,6 +18,7 @@
import ifcopenshell
import ifcopenshell.api
import ifcopenshell.util.element
class Usecase:
@@ -65,7 +66,11 @@ class Usecase:
if not rel.is_a("IfcRelAggregates"):
continue
if len(rel.RelatedObjects) == 1:
return self.file.remove(rel)
history = rel.OwnerHistory
self.file.remove(rel)
if history:
ifcopenshell.util.element.remove_deep2(self.file, history)
return
related_objects = list(rel.RelatedObjects)
related_objects.remove(self.settings["product"])
rel.RelatedObjects = related_objects