Skip to content
Snippets Groups Projects
Commit 3b6e370c authored by florian's avatar florian
Browse files

WIP: Fix datatype bug

parent 42b22d67
No related branches found
No related tags found
2 merge requests!53Release 0.1,!15F fix reference list
......@@ -122,6 +122,21 @@ def check_identical(record1: db.Entity, record2: db.Entity, ignore_id=False):
return True
def _resolve_datatype(prop: db.Property, remote_entity: db.Entity):
if remote_entity.role == "Property":
prop.datatype = remote_entity.datatype
elif remote_entity.role == "RecordType":
prop.datatype = remote_entity.name
else:
raise RuntimeError("Cannot set datatype.")
# Treat lists separately
if isinstance(prop.value, list) and not prop.datatype.startswith("LIST"):
prop.datatype = db.LIST(prop.datatype)
return prop
class Crawler(object):
"""
Crawler class that encapsulates crawling functions.
......@@ -703,6 +718,10 @@ class Crawler(object):
@staticmethod
def execute_inserts_in_list(to_be_inserted):
for record in to_be_inserted:
for prop in record.properties:
entity = db.Entity(name=prop.name).retrieve()
prop = _resolve_datatype(prop, entity)
print("INSERT")
print(to_be_inserted)
if len(to_be_inserted) > 0:
......@@ -719,12 +738,7 @@ class Crawler(object):
if prop.id is None:
entity = db.Entity(name=prop.name).retrieve()
prop.id = entity.id
if entity.role == "Property":
prop.datatype = entity.datatype
elif entity.role == "RecordType":
prop.datatype = entity.name
else:
raise RuntimeError("Cannot set datatype.")
prop = _resolve_datatype(prop, entity)
print("UPDATE")
print(to_be_updated)
if len(to_be_updated) > 0:
......
......@@ -31,6 +31,8 @@ import os
from pytest import raises
import caosdb as db
from newcrawler.converters import JSONFileConverter, DictConverter
from newcrawler.crawl import Crawler
from newcrawler.structure_elements import File, JSONFile
......@@ -60,6 +62,9 @@ def test_json():
assert rec.parents[0].name == "Project"
assert rec.get_property("url") is not None
assert rec.get_property("url").value == "https://site.de/index.php/"
assert rec.get_property("Person") is not None
assert rec.get_property("Person").datatype == db.LIST("Person")
assert len(rec.get_property("Person")) == 2
def test_broken_validation():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment