From bc8df463e5ac17d4cd74acdce1e4130e9e6cf68d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <henrik@trineo.org>
Date: Fri, 2 Jul 2021 20:22:41 +0200
Subject: [PATCH] up

---
 CHANGELOG.md                     |  3 +++
 src/caosadvancedtools/crawler.py | 33 ++++++++++++++++++++------------
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5c1ccfd7..d07084cc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -30,6 +30,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Changed ###
 
+- identifiables of single CFoods are now treated one after the other. This 
+  allows them to have dependencies among each other if they are ordered 
+  correctly
 - identifiables must have at least one property or a name
 * `caosadvancedtools.serverside.helper.init_data_model` also checks the role
   and data type of entities.
diff --git a/src/caosadvancedtools/crawler.py b/src/caosadvancedtools/crawler.py
index 3abd24b3..d25522fe 100644
--- a/src/caosadvancedtools/crawler.py
+++ b/src/caosadvancedtools/crawler.py
@@ -576,6 +576,9 @@ 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(
@@ -593,25 +596,31 @@ carefully and if the changes are ok, click on the following link:
                 ent.id = None
             else:
                 missing = None
+                existing.append(ent)
 
             if missing:
-                #info = "Going to insert the following entities:\n"
-
-                # for ent in missing_identifiables:
-                #    info += str(ent)+"\n"
-                # logger.debug(info)
-
-                # if len(missing_identifiables) == 0:
-                #    logger.debug("No new entities to be inserted.")
-                # else:
-                #        logger.info(
-                #            "Inserting {} Records...".format(
-                #                len(missing_identifiables)))
                 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 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"
+
+            for ent in inserted:
+                info += str(ent)+"\n"
+            logger.debug(info)
+        else:
+            logger.debug("Did not insert any new entities")
 
         logger.debug("Retrieving entities from CaosDB...")
         identifiables.retrieve(unique=True, raise_exception_on_error=False)
-- 
GitLab