From f8c41d870083bf2a05328323bbaf161460af5269 Mon Sep 17 00:00:00 2001
From: Florian Spreckelsen <f.spreckelsen@indiscale.com>
Date: Thu, 24 Jun 2021 13:27:49 +0000
Subject: [PATCH] FIX: Ignore obligatory properties when inserting
 identifiables

---
 CHANGELOG.md                                           | 1 +
 integrationtests/test_crawl_with_datamodel_problems.py | 3 ++-
 src/caosadvancedtools/crawler.py                       | 7 ++++---
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5fbe3b97..5c1ccfd7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -59,6 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 * Fixed an issue where `caosadvancedtools.cache.UpdateCache` would
   cause an `sqlite3.IntegrityError` if more than one change was cached
   for the same entity.
+* #40 Insertion of identifiables with missing obligatory properties
 
 ### Security ###
 
diff --git a/integrationtests/test_crawl_with_datamodel_problems.py b/integrationtests/test_crawl_with_datamodel_problems.py
index 6c212e36..2831bb67 100644
--- a/integrationtests/test_crawl_with_datamodel_problems.py
+++ b/integrationtests/test_crawl_with_datamodel_problems.py
@@ -89,5 +89,6 @@ def test_crawler_with_data_model_problems():
 
     # There should be datamodel problems
     assert len(DataModelProblems.missing) > 0
+
     # Deleted entities should have been identified:
-    assert deleted_entities.issubset(DataModelProblems.missing)
+    assert DataModelProblems.missing.issubset(deleted_entities)
diff --git a/src/caosadvancedtools/crawler.py b/src/caosadvancedtools/crawler.py
index 0a36284a..747c533d 100644
--- a/src/caosadvancedtools/crawler.py
+++ b/src/caosadvancedtools/crawler.py
@@ -544,8 +544,8 @@ carefully and if the changes are ok, click on the following link:
         try:
             if len(cfood.to_be_updated) > 0:
                 logger.info(
-                        "Updating {} Records...".format(
-                            len(cfood.to_be_updated)))
+                    "Updating {} Records...".format(
+                        len(cfood.to_be_updated)))
             guard.safe_update(cfood.to_be_updated, unique=False)
         except FileNotFoundError as e:
             logger.info("Cannot access {}. However, it might be needed for"
@@ -610,7 +610,8 @@ carefully and if the changes are ok, click on the following link:
                 logger.info(
                     "Inserting {} Records...".format(
                         len(missing_identifiables)))
-                guard.safe_insert(missing_identifiables, unique=False)
+                guard.safe_insert(missing_identifiables, unique=False,
+                                  flags={"force-missing-obligatory": "ignore"})
             except Exception as e:
                 DataModelProblems.evaluate_exception(e)
 
-- 
GitLab