From c09504c2682468a84d4399c46ec4b692797cb5c9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com>
Date: Wed, 28 Sep 2022 16:47:56 +0200
Subject: [PATCH] FIX: keyError when only one record has datatype, unit or
 value

---
 src/caosdb/apiutils.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/caosdb/apiutils.py b/src/caosdb/apiutils.py
index 4c839311..88277209 100644
--- a/src/caosdb/apiutils.py
+++ b/src/caosdb/apiutils.py
@@ -338,11 +338,14 @@ def merge_entities(entity_a: Entity, entity_b: Entity):
                 raise NotImplementedError()
 
             for attribute in ("datatype", "unit", "value"):
-                if diff_r1["properties"][key][attribute] is None:
-                    setattr(entity_a.get_property(key), attribute,
-                            diff_r2["properties"][key][attribute])
-                else:
-                    raise RuntimeError("Merge conflict.")
+                if (attribute in diff_r2["properties"][key] and
+                        diff_r2["properties"][key][attribute] is not None):
+                    print(diff_r2["properties"][key][attribute])
+                    if (diff_r1["properties"][key][attribute] is None):
+                        setattr(entity_a.get_property(key), attribute,
+                                diff_r2["properties"][key][attribute])
+                    else:
+                        raise RuntimeError("Merge conflict.")
         else:
             # TODO: This is a temporary FIX for
             #       https://gitlab.indiscale.com/caosdb/src/caosdb-pylib/-/issues/105
-- 
GitLab