diff --git a/backend/inspirehep/records/marshmallow/literature/common/author.py b/backend/inspirehep/records/marshmallow/literature/common/author.py index 551f12d966..7a79383a09 100644 --- a/backend/inspirehep/records/marshmallow/literature/common/author.py +++ b/backend/inspirehep/records/marshmallow/literature/common/author.py @@ -68,11 +68,13 @@ def get_ids(data): author_record = AuthorsRecord.get_record_by_pid_value( get_recid_from_ref(data["record"]) ) + bai = get_first_value_for_schema( + author_record.get("ids", []), "INSPIRE BAI" + ) + if bai: + ids_from_lit_record.append({"schema": "INSPIRE BAI", "value": bai}) except (PIDDoesNotExistError, KeyError): - return missing - bai = get_first_value_for_schema(author_record.get("ids", []), "INSPIRE BAI") - if bai: - ids_from_lit_record.append({"schema": "INSPIRE BAI", "value": bai}) + pass return ids_from_lit_record or missing @pre_dump diff --git a/backend/tests/unit/records/marshmallow/literature/common/test_author.py b/backend/tests/unit/records/marshmallow/literature/common/test_author.py index 00e697581c..65ccf1a84f 100644 --- a/backend/tests/unit/records/marshmallow/literature/common/test_author.py +++ b/backend/tests/unit/records/marshmallow/literature/common/test_author.py @@ -140,3 +140,56 @@ def test_first_author(): result = schema.dumps(dump).data assert expected == orjson.loads(result) + + +def test_authors_ids(): + schema = AuthorSchemaV1() + + dump = { + "full_name": "Castle, Frank", + "ids": [ + {"value": "0000-0002-6152-062X", "schema": "ORCID"}, + ], + } + expected = { + "full_name": "Castle, Frank", + "first_name": "Frank", + "last_name": "Castle", + "ids": [ + {"value": "0000-0002-6152-062X", "schema": "ORCID"}, + ], + } + result = schema.dumps(dump).data + assert expected == orjson.loads(result) + + dump = { + "full_name": "Castle, Frank", + "ids": [{"value": "G.Aad.1", "schema": "INSPIRE BAI"}], + } + expected = { + "full_name": "Castle, Frank", + "first_name": "Frank", + "last_name": "Castle", + "ids": [{"value": "G.Aad.1", "schema": "INSPIRE BAI"}], + } + result = schema.dumps(dump).data + assert expected == orjson.loads(result) + + dump = { + "full_name": "Castle, Frank", + "ids": [ + {"value": "0000-0002-6152-062X", "schema": "ORCID"}, + {"value": "G.Aad.1", "schema": "INSPIRE BAI"}, + ], + } + expected = { + "full_name": "Castle, Frank", + "first_name": "Frank", + "last_name": "Castle", + "ids": [ + {"value": "0000-0002-6152-062X", "schema": "ORCID"}, + {"value": "G.Aad.1", "schema": "INSPIRE BAI"}, + ], + } + result = schema.dumps(dump).data + assert expected == orjson.loads(result)