Skip to content

Commit

Permalink
fix: pydantic ValidationError for "LOM general identifier" integer va…
Browse files Browse the repository at this point in the history
…lues

- when encountering "LOM general identifier"-values as int, those values will be typecast to string from now on
  • Loading branch information
Criamos committed Dec 10, 2024
1 parent 4e60db7 commit 1b3ac42
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions converter/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1b3ac42

Please sign in to comment.