From 131be537c88151505f97595c42e37798c1b07a26 Mon Sep 17 00:00:00 2001 From: Hellow <74311245+HeIIow2@users.noreply.github.com> Date: Mon, 6 May 2024 17:39:53 +0200 Subject: [PATCH] fix: actually merging --- music_kraken/objects/collection.py | 22 ++++++++++++---------- music_kraken/objects/parents.py | 10 ++++++++-- music_kraken/utils/shared.py | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/music_kraken/objects/collection.py b/music_kraken/objects/collection.py index e57cb45..b8b2d4a 100644 --- a/music_kraken/objects/collection.py +++ b/music_kraken/objects/collection.py @@ -88,6 +88,9 @@ class Collection(Generic[T]): def _find_object(self, __object: T, **kwargs) -> Optional[T]: self._remap() + if __object.id in self._indexed_from_id: + return self._indexed_values["id"][__object.id] + for name, value in __object.indexing_values: if value in self._indexed_values[name]: return self._indexed_values[name][value] @@ -138,7 +141,6 @@ class Collection(Generic[T]): :return: """ - if other is None: return if other.id in self._indexed_from_id: @@ -146,13 +148,6 @@ class Collection(Generic[T]): object_trace(f"Appending {other.option_string} to {self}") - # switching collection in the case of push to - for c in self.push_to: - r = c._find_object(other) - if r is not None: - output("found push to", r, other, self, color=BColors.RED, sep="\t") - return c.append(other, **kwargs) - for c in self.pull_from: r = c._find_object(other) @@ -163,6 +158,13 @@ class Collection(Generic[T]): break existing_object = self._find_object(other) + + # switching collection in the case of push to + for c in self.push_to: + r = c._find_object(other) + if r is not None: + output("found push to", r, other, self, color=BColors.RED, sep="\t") + return c.append(other, **kwargs) if existing_object is None: self._append_new_object(other, **kwargs) @@ -195,8 +197,8 @@ class Collection(Generic[T]): if other_collections is None: return - for __object in other_collections: - self.append(__object, **kwargs) + for other_object in other_collections: + self.append(other_object, **kwargs) @property def data(self) -> List[T]: diff --git a/music_kraken/objects/parents.py b/music_kraken/objects/parents.py index ac04e34..a79887a 100644 --- a/music_kraken/objects/parents.py +++ b/music_kraken/objects/parents.py @@ -60,6 +60,13 @@ class InnerData: self._fetched_from.update(__other._fetched_from) for key, value in __other.__dict__.copy().items(): + if key.startswith("_"): + continue + + if hasattr(value, "__is_collection__") and key in self.__dict__: + self.__getattribute__(key).__merge__(value, **kwargs) + continue + # just set the other value if self doesn't already have it if key not in self.__dict__ or (key in self.__dict__ and self.__dict__[key] == self._default_values.get(key)): self.__setattr__(key, value) @@ -67,9 +74,8 @@ class InnerData: # if the object of value implemented __merge__, it merges existing = self.__getattribute__(key) - if hasattr(type(existing), "__merge__"): + if hasattr(existing, "__merge__"): existing.__merge__(value, **kwargs) - continue class OuterProxy: diff --git a/music_kraken/utils/shared.py b/music_kraken/utils/shared.py index b75cf7f..5a40396 100644 --- a/music_kraken/utils/shared.py +++ b/music_kraken/utils/shared.py @@ -15,7 +15,7 @@ __stage__ = os.getenv("STAGE", "prod") DEBUG = (__stage__ == "dev") and True DEBUG_LOGGING = DEBUG and False DEBUG_TRACE = DEBUG and True -DEBUG_OBJECT_TRACE = DEBUG and False +DEBUG_OBJECT_TRACE = DEBUG and True DEBUG_OBJECT_TRACE_CALLSTACK = DEBUG_OBJECT_TRACE and False DEBUG_YOUTUBE_INITIALIZING = DEBUG and False DEBUG_PAGES = DEBUG and False