Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/research_index_backend/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def parse_metadata(

title = clean_html(entity["mainTitle"])

publisher = entity.get("publisher", None)
publisher = entity.get("publisher") or ""

Comment on lines 113 to 116
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change alters metadata parsing by coercing a missing/None publisher to an empty string, but there’s no test exercising the publisher is None (or missing key) case. Add a unit test that parses an OpenAire fixture with publisher: null (and/or no publisher key) and asserts AnonymousArticle.publisher == "" to prevent regressions.

Copilot uses AI. Check for mistakes.
journal_meta = entity.get("journal", "")
if journal_meta:
Expand All @@ -137,7 +137,7 @@ def parse_metadata(
author = parse_author(x)
if author:
all_authors.append(author)
else:
elif authors is not None:
author = parse_author(authors)
if author:
all_authors.append(author)
Expand Down
30 changes: 30 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,36 @@ def test_parse_date(self):
expected = (2021, 5, 13)
assert actual == expected

def test_parse_metadata_null_publisher(self):
"""publisher: null in OpenAire response should produce publisher=''"""
file_path = os.path.join(
"tests", "fixtures", "openaire_v2_simple.json"
)

with open(file_path, "r") as json_file:
json = load(json_file)
json["results"][0]["publisher"] = None

actual = parse_metadata(json, "10.5281/zenodo.4650794", {})

assert len(actual) == 1
assert actual[0].publisher == ""

def test_parse_metadata_null_authors(self):
"""authors: null in OpenAire response should produce an empty authors list"""
file_path = os.path.join(
"tests", "fixtures", "openaire_v2_simple.json"
)

with open(file_path, "r") as json_file:
json = load(json_file)
json["results"][0]["authors"] = None

actual = parse_metadata(json, "10.5281/zenodo.4650794", {})

assert len(actual) == 1
assert actual[0].authors == []

def test_parse_metadata_openaire_v2(self):

file_path = os.path.join(
Expand Down
Loading