Skip to content

Commit 3673b1f

Browse files
committed
including test_if_empty_list_or_none() into get_entities_from_osw() to avoid casting none values
1 parent 1de846c commit 3673b1f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/osw/data/import_utility.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,17 @@ def get_entities_from_osw(
703703
entities_from_osw:
704704
List of entities from OSW.
705705
"""
706+
707+
def test_if_empty_list_or_none(obj) -> bool:
708+
if obj is None:
709+
return True
710+
elif isinstance(obj, list):
711+
if len(obj) == 0:
712+
return True
713+
elif len([item for item in obj if item is not None]) == 0:
714+
return True
715+
return False
716+
706717
if isinstance(category_to_search, str):
707718
category_uuid = category_to_search.split("OSW")[-1]
708719
else: # elif isinstance(category_to_search, uuid_module.UUID):
@@ -726,7 +737,10 @@ def get_entities_from_osw(
726737
if page.exists:
727738
jsondata = page.get_slot_content("jsondata")
728739
jsondata["full_page_title"] = entity
729-
entities_from_osw.append(model_to_cast_to(**jsondata))
740+
kwargs = {
741+
k: v for k, v in jsondata.items() if not test_if_empty_list_or_none(v)
742+
}
743+
entities_from_osw.append(model_to_cast_to(**kwargs))
730744
return entities_from_osw
731745

732746

0 commit comments

Comments
 (0)