From 1b3ac42ce340917ec94931ae035477c8700d28c5 Mon Sep 17 00:00:00 2001 From: criamos <981166+Criamos@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:07:20 +0100 Subject: [PATCH] fix: pydantic ValidationError for "LOM general identifier" integer values - when encountering "LOM general identifier"-values as int, those values will be typecast to string from now on --- converter/pipelines.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/converter/pipelines.py b/converter/pipelines.py index 8ec2fcd3..8163111b 100644 --- a/converter/pipelines.py +++ b/converter/pipelines.py @@ -1190,6 +1190,21 @@ def process_item(self, item: scrapy.Item, spider: scrapy.Spider) -> Optional[scr keywords: list[str] | set[str] | None = lom_general["keyword"] if keywords and isinstance(keywords, set): lom_general["keyword"] = list(keywords) + if "identifier" in lom_general: + identifiers: list[str] | list[int] | None = lom_general["identifier"] + _identifier_strings: list[str] = [] + if identifiers and isinstance(identifiers, list): + for identifier in identifiers: + if identifier and isinstance(identifier, int): + # some APIs provide identifiers as integers, + # but the edu-sharing API expects all values to be of type string + _identifier_strings.append(str(identifier)) + elif identifier and isinstance(identifier, str): + _identifier_strings.append(identifier) + else: + log.warning(f"LOM General identifier {identifier} is not a valid identifier. " + f"(Expected type str, but received {type(identifier)})") + lom_general["identifier"] = _identifier_strings if "technical" in item_adapter["lom"]: lom_technical: dict = item_adapter["lom"]["technical"] if "duration" in lom_technical: