Skip to content
Snippets Groups Projects

Treat dependencies among identifiables

Merged Henrik tom Wörden requested to merge f-ident-deps into dev
4 unresolved threads
@@ -576,44 +576,51 @@ carefully and if the changes are ok, click on the following link:
# looking for matching entities in CaosDB when there is no valid id
# i.e. there was none set from a cache
existing = []
inserted = []
for ent in identifiables:
if ent.id is None or ent.id < 0:
logger.debug("Looking for: {}".format(
ent.id if ent.id is not None else ent.name))
existing = Crawler.find_existing(ent)
found = Crawler.find_existing(ent)
if existing is not None:
ent.id = existing.id
if found is not None:
ent.id = found.id
else:
logger.debug("Id is known of: {}".format(ent))
# insert missing, i.e. those which are not valid
missing_identifiables = db.Container()
missing_identifiables.extend([ent for ent in identifiables
if ent.id is None or ent.id < 0])
# TODO the following should not be necessary. Fix it
for ent in missing_identifiables:
ent.id = None
# insert missing, i.e. those which are not valid
if ent.id is None or ent.id < 0:
missing = ent
ent.id = None
else:
missing = None
existing.append(ent)
if len(missing_identifiables) > 0:
info = "Going to insert the following entities:\n"
if missing:
try:
guard.safe_insert(missing, unique=False,
flags={"force-missing-obligatory": "ignore"})
inserted.append(ent)
except Exception as e:
DataModelProblems.evaluate_exception(e)
if len(existing) > 0:
info = "Identified the following existing entities:\n"
for ent in missing_identifiables:
for ent in existing:
info += str(ent)+"\n"
logger.debug(info)
else:
logger.debug("Did not identify any existing entities")
if len(inserted) > 0:
info = "Inserted the following entities:\n"
if len(missing_identifiables) == 0:
logger.debug("No new entities to be inserted.")
for ent in inserted:
info += str(ent)+"\n"
logger.debug(info)
else:
try:
logger.info(
"Inserting {} Records...".format(
len(missing_identifiables)))
guard.safe_insert(missing_identifiables, unique=False,
flags={"force-missing-obligatory": "ignore"})
except Exception as e:
DataModelProblems.evaluate_exception(e)
logger.debug("Did not insert any new entities")
logger.debug("Retrieving entities from CaosDB...")
identifiables.retrieve(unique=True, raise_exception_on_error=False)
Loading