From 36746051126627b3b3b5a94faad82b9d7ba2de7d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <henrik@trineo.org>
Date: Wed, 6 Apr 2022 16:28:44 +0200
Subject: [PATCH] WIP: should this code snippet be used?

---
 src/caosadvancedtools/cfoods/h5.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/caosadvancedtools/cfoods/h5.py b/src/caosadvancedtools/cfoods/h5.py
index cbf9d0ba..2a29f9fb 100644
--- a/src/caosadvancedtools/cfoods/h5.py
+++ b/src/caosadvancedtools/cfoods/h5.py
@@ -172,6 +172,20 @@ class H5CFood(AbstractFileCFood):
         self.to_be_inserted = db.Container()
         self.insert_missing_structure(self.structure)
 
+        for el in self.to_be_inserted:
+            if isinstance(el, db.File):
+                el.retrieve()
+
+        valids = []
+
+        for el in self.to_be_inserted:
+            if el.is_valid():
+                valids.append(el.id)
+
+        for el in self.to_be_inserted:
+            if el.id is not None and el.id in valids:
+                self.to_be_inserted.remove(el)
+
         # TODO this is a workaround due to the fact that the caosdb library
         # changes the objects in the Container if it is inserted. The graph
         # structure is flattened. I.e. references to other entity objects are
-- 
GitLab