From 76184d95b3970c436140860c243f51325e46efc4 Mon Sep 17 00:00:00 2001
From: florian <f.spreckelsen@inidscale.com>
Date: Wed, 11 Jan 2023 14:43:18 +0100
Subject: [PATCH] DRAFT: Implement possible fix for missing list datatype

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

diff --git a/src/caosdb/apiutils.py b/src/caosdb/apiutils.py
index f3195b8e..6a6d2daa 100644
--- a/src/caosdb/apiutils.py
+++ b/src/caosdb/apiutils.py
@@ -37,7 +37,7 @@ from subprocess import call
 from typing import Optional, Any, Dict, List
 
 from caosdb.common.datatype import (BOOLEAN, DATETIME, DOUBLE, FILE, INTEGER,
-                                    REFERENCE, TEXT, is_reference)
+                                    LIST, REFERENCE, TEXT, is_reference)
 from caosdb.common.models import (Container, Entity, File, Property, Query,
                                   Record, RecordType, execute_query,
                                   get_config, SPECIAL_ATTRIBUTES)
@@ -442,6 +442,16 @@ 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:
-- 
GitLab