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

warn in case of multiprop

parent 0c1f0d59
No related branches found
No related tags found
2 merge requests!178FIX: #96 Better error output for crawl.py script.,!167Sync Graph
......@@ -28,6 +28,7 @@ from typing import TYPE_CHECKING, Any, Optional, Union
import linkahead as db
import yaml
from linkahead.common.models import Parent, _ParentList, _Properties
from warnings import warn
from .exceptions import ImpossibleMergeError
......@@ -78,6 +79,7 @@ class SyncNode:
self.description = entity.description
self.parents = _ParentList().extend(entity.parents)
self.properties = _Properties().extend(entity.properties)
self._check_for_multiproperties()
# other members
self.identifiable: Optional[Identifiable] = None
self.registered_identifiable = registered_identifiable
......@@ -216,6 +218,20 @@ class SyncNode:
+ "=====================================================\n"
)
def _check_for_multiproperties(self):
""" warns if multiproperties are present """
ids = set()
names = set()
for p in self.properties:
if p.name is not None:
if p.name in names:
warn("Multiproperties are not supported by the crawler.")
names.add(p.name)
if p.id is not None:
if p.id in ids:
warn("Multiproperties are not supported by the crawler.")
ids.add(p.id)
def parent_in_list(parent: Parent, plist: _ParentList) -> bool:
"""helper function that checks whether a parent with the same name or ID is in the plist"""
......
......@@ -232,6 +232,12 @@ def test_export_node():
.add_property(name="a", value='b')
.add_property(name="a", value='a'))
# there should be a warning when multiproperties are used
with pytest.warns(UserWarning) as caught:
SyncNode(rec_a)
messages = {str(w.message) for w in caught}
assert ("Multiproperties are not supported by the crawler.") in messages
with pytest.raises(ImpossibleMergeError):
exp = SyncNode(rec_a).export_entity()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment