diff --git a/src/caoscrawler/sync_node.py b/src/caoscrawler/sync_node.py index 80a7e4a183a0fe3685c0c1873935ea43766125c7..0dff53d5a87e60cfc0ef57b4268d627add209257 100644 --- a/src/caoscrawler/sync_node.py +++ b/src/caoscrawler/sync_node.py @@ -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""" diff --git a/unittests/test_sync_node.py b/unittests/test_sync_node.py index 31f54a3b2f144c91351fdabe93589363af4486b1..16b5fd93b8ed790e0be22b1acf4f965c10fc69c1 100644 --- a/unittests/test_sync_node.py +++ b/unittests/test_sync_node.py @@ -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()