From 4bff2549dd2758f7e6348aaa3fa0bb1c41392a6d Mon Sep 17 00:00:00 2001 From: huyenngn Date: Wed, 20 Mar 2024 10:54:25 +0100 Subject: [PATCH] fix: Implement delete for RoleTagAccessors --- capellambse/model/common/accessors.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/capellambse/model/common/accessors.py b/capellambse/model/common/accessors.py index b48cb5200..5dc47d70e 100644 --- a/capellambse/model/common/accessors.py +++ b/capellambse/model/common/accessors.py @@ -1811,7 +1811,28 @@ def delete( elmlist: ElementListCouplingMixin, obj: element.ModelObject, ) -> None: - raise NotImplementedError("NYI") + assert obj._model is elmlist._model + model = obj._model + all_elements = list(model._loader.iterdescendants_xt(obj._element)) + [ + obj._element + ] + with contextlib.ExitStack() as stack: + for elm in all_elements: + if elm.get("id") is None: + continue + + obj = element.GenericElement.from_model(model, elm) + for ref, attr, _ in model.find_references(obj): + acc = getattr(type(ref), attr) + if acc is self or not isinstance(acc, WritableAccessor): + continue + stack.enter_context(acc.purge_references(ref, obj)) + + elm = obj._element + parent = elm.getparent() + assert parent is not None + model._loader.idcache_remove(elm) + parent.remove(elm) @contextlib.contextmanager def purge_references(