fix: recursion depth error

This commit is contained in:
Hazel 2024-04-18 15:30:04 +02:00
parent 85923e2a79
commit 662f207529
2 changed files with 8 additions and 22 deletions

View File

@ -164,15 +164,7 @@ class OuterProxy:
self._add_other_db_objects(key, value) self._add_other_db_objects(key, value)
def __hash__(self): def __hash__(self):
""" return id(self)
:raise: IsDynamicException
:return:
"""
if self.dynamic:
return id(self._inner)
return self.id
def __eq__(self, other: Any): def __eq__(self, other: Any):
return self.__hash__() == other.__hash__() return self.__hash__() == other.__hash__()
@ -189,7 +181,6 @@ class OuterProxy:
if __other is None: if __other is None:
return return
object_trace(f"merging {type(self).__name__} [{self.title_string} | {self.id}] with {type(__other).__name__} [{__other.title_string} | {__other.id}] called by [{' | '.join(f'{s.function} {Path(s.filename).name}:{str(s.lineno)}' for s in inspect.stack()[1:4])}]")
a = self a = self
b = __other b = __other
@ -201,7 +192,8 @@ class OuterProxy:
if len(b._inner._refers_to_instances) > len(a._inner._refers_to_instances): if len(b._inner._refers_to_instances) > len(a._inner._refers_to_instances):
a, b = b, a a, b = b, a
a._inner.__merge__(b._inner, override=override) object_trace(f"merging {type(a).__name__} [{a.title_string} | {a.id}] with {type(b).__name__} [{b.title_string} | {b.id}] called by [{' | '.join(f'{s.function} {Path(s.filename).name}:{str(s.lineno)}' for s in inspect.stack()[1:5])}]")
for collection, child_collection in b._inner._is_collection_child.items(): for collection, child_collection in b._inner._is_collection_child.items():
try: try:
collection.children.remove(child_collection) collection.children.remove(child_collection)
@ -213,13 +205,14 @@ class OuterProxy:
collection.parents.remove(parent_collection) collection.parents.remove(parent_collection)
except ValueError: except ValueError:
pass pass
old_inner = b._inner old_inner = b._inner
a._inner._refers_to_instances.update(b._inner._refers_to_instances)
for instance in b._inner._refers_to_instances: for instance in b._inner._refers_to_instances.copy():
instance._inner = a._inner instance._inner = a._inner
a._inner._refers_to_instances.add(instance)
a._inner.__merge__(old_inner, override=override)
del old_inner del old_inner
def __merge__(self, __other: Optional[OuterProxy], override: bool = False): def __merge__(self, __other: Optional[OuterProxy], override: bool = False):

View File

@ -104,14 +104,7 @@ class Source(OuterProxy):
('url', self.url), ('url', self.url),
('audio_url', self.audio_url), ('audio_url', self.audio_url),
] ]
def __merge__(self, __other: Source, override: bool = False):
if override:
self.audio_url = __other.audio_url
if self.audio_url is None or (override and __other.audio_url is not None):
self.audio_url = __other.audio_url
def __str__(self): def __str__(self):
return self.__repr__() return self.__repr__()