From b91f936fe60ecb1cf3b65388553b7ccccbf16dba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com>
Date: Mon, 25 Sep 2023 20:45:53 +0200
Subject: [PATCH] up

---
 src/caosdb/apiutils.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/caosdb/apiutils.py b/src/caosdb/apiutils.py
index a46e3037..fec520b5 100644
--- a/src/caosdb/apiutils.py
+++ b/src/caosdb/apiutils.py
@@ -178,6 +178,16 @@ def getCommitIn(folder):
     return get_commit_in(folder)
 
 
+def entity_and_id(this, that):
+    """
+    returns true iff exactly one of this and that is an Entity with an ID and the other is an
+    integer
+    """
+    return (
+        (isinstance(this, Entity) and this.id is not None and isinstance(that, int))
+        or (isinstance(this, int) and isinstance(that, Entity) and this.id is not None))
+
+
 def compare_entities(old_entity: Entity, new_entity: Entity, compare_referenced_records: bool = False):
     """Compare two entites.
 
@@ -279,6 +289,15 @@ def compare_entities(old_entity: Entity, new_entity: Entity, compare_referenced_
             if (prop.value != matching[0].value):
                 # basic comparison of value objects says they are different
                 same_value = False
+
+                # one Entity with ID and one int?
+                if (sufficient_id and ):
+                    if ((isinstance(matching[0].value, int)
+                         and prop.value.id == matching[0].value)
+                            or (isinstance(prop.value, int)
+                                and prop.value == matching[0].value.id)):
+                        same_value = True
+
                 if compare_referenced_records:
                     # scalar reference
                     if isinstance(prop.value, Entity) and isinstance(matching[0].value, Entity):
-- 
GitLab