Skip to content

Commit

Permalink
dumper: added condition for no parent
Browse files Browse the repository at this point in the history
  • Loading branch information
0einstein0 authored and ptamarit committed Oct 8, 2024
1 parent d3a2750 commit 8998905
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion invenio_rdm_records/records/dumpers/subject_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ def dump(self, record, data):

def build_hierarchy(parents_str, current_subject_id):
"""Build the hierarchy by progressively combining parent notations."""
if not parents_str:
return [
current_subject_id
] # No parents, so the hierarchy is just the current ID.

parents = parents_str.split(self._splitchar) # Split the parent notations
hierarchy = []
current_hierarchy = parents[0] # Start with the top-level parent
Expand All @@ -87,7 +92,7 @@ def build_hierarchy(parents_str, current_subject_id):
for subject in subjects:
parents = subject.get("props", {}).get("parents", "")
current_subject_id = subject.get("id", "")
if parents and current_subject_id:
if current_subject_id:
subject_hierarchy = build_hierarchy(parents, current_subject_id)
subject.setdefault("props", {})["hierarchy"] = subject_hierarchy

Expand Down

0 comments on commit 8998905

Please sign in to comment.