From 544bc63ae35f5a4307b6165c3d56be6c451b2062 Mon Sep 17 00:00:00 2001
From: florian <f.spreckelsen@inidscale.com>
Date: Wed, 11 Jan 2023 15:20:39 +0100
Subject: [PATCH] FIX: Raise correct error, but don't infer list datatypes

---
 CHANGELOG.md               |  4 ++--
 src/caosdb/apiutils.py     | 10 ----------
 unittests/test_apiutils.py |  5 +++--
 3 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index e8b45a87..ac82507b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,8 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Fixed ###
 
 * [#82](https://gitlab.com/caosdb/caosdb-pylib/-/issues/82) Merging an entity
-  with properties with missing datatype leads to Exception - list datatypes are
-  now inferred from scalar datatype in force merges.
+  with properties with missing datatype leads to Exception - The correct
+  exception is raised in case of a missing LIST datatype.
 
 ### Security ###
 
diff --git a/src/caosdb/apiutils.py b/src/caosdb/apiutils.py
index 6a6d2daa..974b0ea7 100644
--- a/src/caosdb/apiutils.py
+++ b/src/caosdb/apiutils.py
@@ -442,16 +442,6 @@ def merge_entities(entity_a: Entity, entity_b: Entity, merge_references_with_emp
                         setattr(entity_a.get_property(key), attribute,
                                 diff_r2["properties"][key][attribute])
                     elif force:
-                        if attribute == "value":
-                            # Very special case of a property that has a scalar
-                            # datatype being fored to a list value without
-                            # having been assigned the correct datatype before.
-                            if isinstance(diff_r2["properties"][key][attribute], list):
-                                if ((entity_a.get_property(key).datatype is not None) and
-                                        (not entity_a.get_property(key).datatype.startswith("LIST<"))):
-                                    entity_a.get_property(key).datatype = LIST(
-                                        entity_a.get_property(key).datatype)
-
                         setattr(entity_a.get_property(key), attribute,
                                 diff_r2["properties"][key][attribute])
                     else:
diff --git a/unittests/test_apiutils.py b/unittests/test_apiutils.py
index f10021dd..bda381cf 100644
--- a/unittests/test_apiutils.py
+++ b/unittests/test_apiutils.py
@@ -571,5 +571,6 @@ def test_merge_missing_list_datatype_82():
 
     recA = db.Record().add_property("a", 5, datatype="B")
     recB_without_DT = db.Record().add_property("a", [1, 2])
-    merge_entities(recA, recB_without_DT, force=True)
-    assert recA.get_property("a").datatype == "LIST<B>"
+    with pytest.raises(TypeError) as te:
+        merge_entities(recA, recB_without_DT, force=True)
+    assert "Invalid datatype: List valued properties" in str(te.value)
-- 
GitLab