Skip to content
Snippets Groups Projects
Commit 5bcefcca authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

MAINT: do not allow Identifiable for nodes without registered ident

parent 28b1b816
Branches
Tags
2 merge requests!178FIX: #96 Better error output for crawl.py script.,!167Sync Graph
Pipeline #50843 passed with warnings
...@@ -288,72 +288,68 @@ startswith: bool, optional ...@@ -288,72 +288,68 @@ startswith: bool, optional
Identifiable, the identifiable for record. Identifiable, the identifiable for record.
""" """
registered_identifiable = se.registered_identifiable
property_name_list_A = [] property_name_list_A = []
property_name_list_B = [] property_name_list_B = []
identifiable_props = {} identifiable_props = {}
name = None name = None
# TODO if se.registered_identifiable is None:
# if registered_identifiable is None: raise ValueError("no register_identifiable")
# raise ValueError("no register_identifiable")
if registered_identifiable is not None: # fill the values:
# fill the values: for prop in se.registered_identifiable.properties:
for prop in registered_identifiable.properties: if prop.name == "name":
if prop.name == "name": name = se.name
name = se.name continue
continue # problem: what happens with multi properties?
# problem: what happens with multi properties? # case A: in the registered identifiable
# case A: in the registered identifiable # case B: in the identifiable
# case B: in the identifiable
# treated elsewhere
if prop.name.lower() == "is_referenced_by":
for el in identifiable_backrefs:
assert isinstance(el, SyncNode)
if len(identifiable_backrefs) == 0:
raise MissingReferencingEntityError(
f"Could not find referencing entities of type(s): {prop.value}\n"
f"for registered identifiable:\n{registered_identifiable}\n"
f"There were {len(identifiable_backrefs)} referencing entities to choose from.\n"
f"This error can also occur in case of merge conflicts in the referencing entities."
)
elif len([e.id for e in identifiable_backrefs if el.id is None]) > 0:
raise RuntimeError(
f"Referencing entity has no id"
)
continue
options = [p.value for p in se.properties if p.name == prop.name] # treated elsewhere
if len(options) == 0: if prop.name.lower() == "is_referenced_by":
raise MissingIdentifyingProperty( for el in identifiable_backrefs:
f"The following record is missing an identifying property:\n" assert isinstance(el, SyncNode)
f"RECORD\n{se}\nIdentifying PROPERTY\n{prop.name}" if len(identifiable_backrefs) == 0:
raise MissingReferencingEntityError(
f"Could not find referencing entities of type(s): {prop.value}\n"
f"for registered identifiable:\n{se.registered_identifiable}\n"
f"There were {len(identifiable_backrefs)} referencing entities to choose from.\n"
f"This error can also occur in case of merge conflicts in the referencing entities."
) )
for ii, el in enumerate(options): elif len([e.id for e in identifiable_backrefs if el.id is None]) > 0:
if isinstance(el, SyncNode): raise RuntimeError(
options[ii] = el.id f"Referencing entity has no id"
if el.id is None: )
raise RuntimeError("Reference to unchecked in identifiable:\n" continue
f"{prop.name}:\n{el}")
else: options = [p.value for p in se.properties if p.name == prop.name]
options[ii] = el if len(options) == 0:
if not all([f == options[0] for f in options]): raise MissingIdentifyingProperty(
raise RuntimeError("differing prop values ") f"The following record is missing an identifying property:\n"
f"RECORD\n{se}\nIdentifying PROPERTY\n{prop.name}"
identifiable_props[prop.name] = options[0] )
property_name_list_A.append(prop.name) for ii, el in enumerate(options):
if isinstance(el, SyncNode):
# check for multi properties in the record: options[ii] = el.id
for prop in property_name_list_A: if el.id is None:
property_name_list_B.append(prop) raise RuntimeError("Reference to unchecked in identifiable:\n"
if (len(set(property_name_list_B)) != len(property_name_list_B) or len( f"{prop.name}:\n{el}")
set(property_name_list_A)) != len(property_name_list_A)): else:
raise RuntimeError( options[ii] = el
"Multi properties used in identifiables could cause unpredictable results and " if not all([f == options[0] for f in options]):
"are not allowed. You might want to consider a Property with a list as value.") raise RuntimeError("differing prop values ")
identifiable_props[prop.name] = options[0]
property_name_list_A.append(prop.name)
# check for multi properties in the record:
for prop in property_name_list_A:
property_name_list_B.append(prop)
if (len(set(property_name_list_B)) != len(property_name_list_B) or len(
set(property_name_list_A)) != len(property_name_list_A)):
raise RuntimeError(
"Multi properties used in identifiables could cause unpredictable results and "
"are not allowed. You might want to consider a Property with a list as value.")
# use the RecordType of the registered Identifiable if it exists # use the RecordType of the registered Identifiable if it exists
# We do not use parents of Record because it might have multiple # We do not use parents of Record because it might have multiple
...@@ -361,8 +357,7 @@ startswith: bool, optional ...@@ -361,8 +357,7 @@ startswith: bool, optional
return Identifiable( return Identifiable(
record_id=se.id, record_id=se.id,
path=se.path, path=se.path,
record_type=(registered_identifiable.parents[0].name record_type=se.registered_identifiable.parents[0].name,
if registered_identifiable else None),
name=name, name=name,
properties=identifiable_props, properties=identifiable_props,
backrefs=[e.id for e in identifiable_backrefs] backrefs=[e.id for e in identifiable_backrefs]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment