From 667a09b8af00b7612d5b6bd27ba385cee907a1a5 Mon Sep 17 00:00:00 2001 From: Ales Kutsepau Date: Wed, 18 Feb 2026 16:20:21 +0100 Subject: [PATCH] Changed the finalizer function for __type_dict This is a temporary quickfix, until __type_dict is pruned from the codebase. The need for this change is due to serialization of baseobjects creating temprorary objects. When the temp objects are finally GC'd, their name in the _store dict might be already taken by an actual (not a temporary) Parameter. GC then calls the the __type_dict's finalizer. In the old solution it was the prune method, which removes the key from __type_dict as well as _store (which might be an actual Parameter by that time). The new solution provides a method to delete keys only from the __type_dict, since removing keys from _store might affect actual Parameters and since _store is a weakref dict anyway. --- src/easyscience/global_object/map.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/easyscience/global_object/map.py b/src/easyscience/global_object/map.py index 33636c68..a9d0b576 100644 --- a/src/easyscience/global_object/map.py +++ b/src/easyscience/global_object/map.py @@ -169,7 +169,7 @@ def add_vertex(self, obj: object, obj_type: str = None): self._store[name] = obj entry_list = _EntryList() - entry_list.finalizer = weakref.finalize(obj, self.prune, name) + entry_list.finalizer = weakref.finalize(obj, self.prune_type_dict, name) entry_list.type = obj_type self.__type_dict[name] = entry_list # Add objects type to the list of types @@ -210,6 +210,10 @@ def prune_vertex_from_edge(self, parent_obj, child_obj): if vertex1 in self.__type_dict and vertex2 in self.__type_dict[vertex1]: del self.__type_dict[vertex1][self.__type_dict[vertex1].index(vertex2)] + def prune_type_dict(self, key: str): + if key in self.__type_dict: + del self.__type_dict[key] + def prune(self, key: str): if key in self.__type_dict: del self.__type_dict[key]