Compare commits

..

2 Commits

Author SHA1 Message Date
f000ad4484 fix: some crashes 2024-04-17 18:13:03 +02:00
7e4ba0b1a0 fix: clean mapping 2024-04-17 18:00:41 +02:00
2 changed files with 14 additions and 6 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]
@ -281,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

@ -194,17 +194,23 @@ class OuterProxy:
if a._inner is b._inner:
return
# switch instances if more efficient
if len(b._inner._refers_to_instances) > len(a._inner._refers_to_instances):
a, b = b, a
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)