diff --git a/swh/storage/converters.py b/swh/storage/converters.py --- a/swh/storage/converters.py +++ b/swh/storage/converters.py @@ -5,6 +5,8 @@ import datetime +from typing import Optional, Dict + from swh.core.utils import decode_with_escape, encode_with_unescape from swh.model import identifiers from swh.model.hashutil import MultiHash @@ -39,19 +41,22 @@ return author -def db_to_author(fullname, name, email): +def db_to_author( + fullname: Optional[bytes], name: Optional[bytes], email: Optional[bytes] +) -> Optional[Dict[str, Optional[bytes]]]: """Convert the DB representation of an author to a swh-model author. Args: - id (long): the author's identifier fullname (bytes): the author's fullname name (bytes): the author's name email (bytes): the author's email Returns: - dict: a dictionary with four keys: id, fullname, name and email, or - None if the id is None + a dictionary with three keys (fullname, name and email), or + None if all the arguments are None. """ + if (fullname, name, email) == (None, None, None): + return None return { "fullname": fullname, "name": name, diff --git a/swh/storage/tests/test_converters.py b/swh/storage/tests/test_converters.py --- a/swh/storage/tests/test_converters.py +++ b/swh/storage/tests/test_converters.py @@ -55,6 +55,14 @@ } +def test_db_to_author_none(): + # when + actual_author = converters.db_to_author(None, None, None) + + # then + assert actual_author is None + + def test_db_to_revision(): # when actual_revision = converters.db_to_revision(