Skip to content
Snippets Groups Projects
Commit 5fc3e1c1 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

Merge branch 'f-handle-lists-in-crawler' into 'dev'

F handle lists in crawler

See merge request caosdb/caosdb-advanced-user-tools!89
parents 3ddc7619 3ca09471
No related branches found
No related tags found
1 merge request!22Release 0.3
Pipeline #14851 passed
......@@ -71,6 +71,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
of a RecordType. This is fixed now.
* #52 `XLSimporter.read_xls` throwed a wrong error when reading from a file with a wrong ending.
Now, a `DataInconsistencyError` is raised instead of a ValueError.
* List properties are no longer updated unnecessarily by the crawler.
### Security ###
......
......@@ -47,6 +47,7 @@ from abc import ABCMeta, abstractmethod
from datetime import datetime
import caosdb as db
from caosdb.common.models import Entity
from caosdb.exceptions import (BadQueryError, EmptyUniqueQueryError,
QueryNotUniqueError, TransactionError)
......@@ -662,12 +663,18 @@ def assure_has_property(entity, name, value, to_be_updated=None,
if isinstance(value, db.Entity):
value = value.id
if isinstance(value, list):
value = [i.id if isinstance(i, db.Entity) else i for i in value]
for el in possible_properties:
tmp_value = el.value
if isinstance(tmp_value, db.Entity):
tmp_value = el.value.id
if isinstance(tmp_value, list):
tmp_value = [i.id if isinstance(i, db.Entity) else i for i in tmp_value]
if tmp_value == value:
contained = True
......
......@@ -190,6 +190,35 @@ class InsertionTest(unittest.TestCase):
value=new_int, to_be_updated=to_be_updated)
assert to_be_updated[0] is entity
"""Test properties with lists"""
rec1 = db.Record(id=12345)
rec1.add_property("Exp", value=[98765], datatype=db.LIST("Exp"))
rec2 = db.Record(id=98765)
update = []
# compare Entity with id
assure_has_property(rec1, "Exp", [rec2], to_be_updated=update)
assert len(update) == 0
update = []
# compare id with id
assure_has_property(rec1, "Exp", [98765], to_be_updated=update)
assert len(update) == 0
update = []
# compare id with different list of ids
assure_has_property(rec1, "Exp2", [98765, 444, 555],
to_be_updated=update)
assert len(update) == 1
rec = db.Record(id=666666)
rec3 = db.Record(id=777777)
rec.add_property("Exp", value=[888888, rec3], datatype=db.LIST("Exp"))
rec2 = db.Record(id=888888)
update = []
# compare id and Entity with id and Entity
# i.e. check that conversion from Entity to id works in both
# directions.
assure_has_property(rec, "Exp", [rec2, 777777], to_be_updated=update)
assert len(update) == 0
def test_property_is(self):
"""Test properties with string, int, float, and Boolean values"""
entity = db.Record()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment