fix: some crashes

This commit is contained in:
Hazel 2024-04-17 18:13:03 +02:00
parent 7e4ba0b1a0
commit f000ad4484
2 changed files with 14 additions and 7 deletions

View File

@ -60,8 +60,10 @@ class Collection(Generic[T]):
self._contains_ids.remove(__object.id)
for name, value in self._id_to_index_values[__object.id]:
del self._indexed_values[name]
del self._indexed_to_objects[value]
if name in self._indexed_values:
del self._indexed_values[name]
if value in self._indexed_to_objects:
del self._indexed_to_objects[value]
del self._id_to_index_values[__object.id]
@ -228,7 +230,6 @@ class Collection(Generic[T]):
else:
# merge only if the two objects are not the same
if existing_object.id == __object.id:
exit()
return
append_to._unmap_element(existing_object)
@ -282,7 +283,7 @@ class Collection(Generic[T]):
yield from c.__iter__(finished_ids=finished_ids)
def __merge__(self, __other: Collection, override: bool = False):
self.extend(__other.__iter__())
self.extend(__other)
def __getitem__(self, item: int):
if item < len(self._data):

View File

@ -201,10 +201,16 @@ class OuterProxy:
a._inner.__merge__(b._inner, override=override)
for collection, child_collection in b._inner._is_collection_child.items():
collection.children.remove(child_collection)
try:
collection.children.remove(child_collection)
except ValueError:
pass
for collection, parent_collection in b._inner._is_collection_parent.items():
collection.parents.remove(parent_collection)
try:
collection.parents.remove(parent_collection)
except ValueError:
pass
a._inner._refers_to_instances.update(b._inner._refers_to_instances)