Skip to content
Snippets Groups Projects
Commit b3b34c92 authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

BUG: Add missing information in ImpossibleMergeError message

parent 7d05e02f
No related branches found
No related tags found
2 merge requests!184Release 0.9.1,!183F improve error messages
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment