Skip to content

Commit dac2b26

Browse files
committed
safer people merging
1 parent b071836 commit dac2b26

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/somesy/core/writer.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ def _sync_person_list(
251251
252252
"""
253253
old_people: List[Union[Person, Entity]] = self._parse_people(old)
254+
if old_people is None or len(old_people) == 0:
255+
return new
256+
if new is None or len(new) == 0:
257+
return old_people
254258
return self._merge_person_metadata(old_people, new)
255259

256260
def _sync_authors(self, metadata: ProjectMetadata) -> None:
@@ -259,7 +263,10 @@ def _sync_authors(self, metadata: ProjectMetadata) -> None:
259263
This method is existing for the publication_author special case
260264
when synchronizing to CITATION.cff.
261265
"""
262-
self.authors = self._sync_person_list(self.authors, metadata.authors())
266+
if self.authors is None or len(self.authors) == 0:
267+
self.authors = metadata.authors()
268+
else:
269+
self.authors = self._sync_person_list(self.authors, metadata.authors())
263270

264271
def sync(self, metadata: ProjectMetadata) -> None:
265272
"""Sync output file with other metadata files."""
@@ -301,7 +308,7 @@ def _parse_people(cls, people: Optional[List[Any]]) -> List[Union[Person, Entity
301308
# remove None values
302309
people = [p for p in people if p is not None]
303310

304-
people = list(map(cls._to_person, people or []))
311+
people = list(map(lambda p: cls._to_person(p), people or []))
305312
return people
306313

307314
# ----
@@ -345,7 +352,7 @@ def description(self, description: str) -> None:
345352
def authors(self):
346353
"""Return the authors of the project."""
347354
authors = self._get_property(self._get_key("authors"))
348-
if authors is None:
355+
if authors is None or len(authors) == 0:
349356
return []
350357

351358
# only return authors that can be converted to Person

0 commit comments

Comments
 (0)