diff --git a/src/caoscrawler/sync_node.py b/src/caoscrawler/sync_node.py index 141e743bffa09f0caf661bcd1939a4233cb7249c..1acb54938476796b6baf61c3c52f747dd5cfcba8 100644 --- a/src/caoscrawler/sync_node.py +++ b/src/caoscrawler/sync_node.py @@ -87,13 +87,25 @@ class SyncNode(db.Entity): self.registered_identifiable = registered_identifiable def update(self, other: SyncNode) -> None: - """update this node with information of given ``other`` SyncNode. + """Update this node with information of given ``other`` SyncNode. + + parents are added if they are not yet in the list properties + are added in any case. This may lead to duplication of + properties. We allow this duplication here and remove it when + we create a db.Entity (export_entity function) because if + property values are SyncNode objects, they might not be + comparable (no ID, no identifiable) yet. + + Raises + ------ + ValueError: + The `other` SyncNode doesn't share identifiables with + `this` SyncNode, so they can't be merged. + ImpossibleMergeError: + The two SyncNodes are incompatible in their attributes + like "id", "role", "path", "file", "name", or + "description". - parents are added if they are not yet in the list - properties are added in any case. This may lead to duplication of properties. - We allow this duplication here and remove it when we create a db.Entity (export_entity - function) because if property values are SyncNode objects, they might not be comparable (no - ID, no identifiable) yet. """ if other.identifiable is not None and self.identifiable is not None: @@ -121,8 +133,9 @@ class SyncNode(db.Entity): f"Trying to update {attr} but this would lead to an " f"override of the value '{self.__getattribute__(attr)}' " f"by the value '{other.__getattribute__(attr)}'", - pname=attr, values=(self.__getattribute__(attr), - other.__getattribute__(attr)) + pname=attr, + value_a=self.__getattribute__(attr), + value_b=other.__getattribute__(attr) ) for p in other.parents: if not parent_in_list(p, self.parents): @@ -136,6 +149,13 @@ class SyncNode(db.Entity): Properties are only added once (based on id or name). If values do not match, an Error is raised. If values are SyncNode objects with IDs, they are considered equal if their IDs are equal. + + Raises + ------ + RuntimeError: + In case of a unsupported role, so no Entity can't be created. + ImpossibleMergeError: + In case of conflicting property values in this SyncNode. """ ent = None if self.role == "Record": @@ -175,16 +195,10 @@ class SyncNode(db.Entity): unequal = True if unequal: - logger.error( - "The Crawler is trying to create an entity," - " but there are conflicting property values." - f"Problematic Property: {p.name}\n" - f"First value:\n{entval}\n" - f"Second value:\n{pval}\n" - f"{self}" - ) ime = ImpossibleMergeError( - "Cannot merge Entities", pname=p.name, values=(entval, pval) + f"The crawler is trying to create an entity \n\n{self}\n\nbut there are " + "conflicting property values.", + pname=p.name, value_a=entval, value_b=pval ) raise ime return ent