Skip to content

Commit

Permalink
Merge pull request #78 from sul-dlss-labs/openalex-bugfix
Browse files Browse the repository at this point in the history
Handle single DOI invalid in OpenAlex
  • Loading branch information
lwrubel authored Jul 9, 2024
2 parents 82286d1 + 61afdcd commit 2dfbc57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rialto_airflow/harvest/openalex.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def publications_from_dois(dois: list):
pubs = Works().filter(doi=doi).get()
if len(pubs) > 1:
logging.warn(f"Found multiple publications for DOI {doi}")
yield normalize_publication(pubs[0])
if len(pubs) > 0:
yield normalize_publication(pubs[0])
except api.QueryError as e:
logging.error(f"OpenAlex QueryError for {doi}: {e}")
continue
Expand Down
11 changes: 11 additions & 0 deletions test/harvest/test_openalex.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ def test_publications_from_invalid_dois(caplog):
), "logs error message"


def test_publications_from_invalid_with_comma(caplog):
# OpenAlex will interpret a DOI string with a comma as two DOIs but
# Does not return a result for the first half even if valid. Will return an empty list
invalid_doi = ["10.1002/cncr.33546,-(wileyonlinelibrary.com)"]
assert len(list(openalex.publications_from_dois(invalid_doi))) == 0
assert (
"OpenAlex QueryError for 10.1002/cncr.33546,-(wileyonlinelibrary.com): Invalid query parameter"
in caplog.text
), "logs error message"


def test_publications_csv(tmp_path):
pubs_csv = tmp_path / "openalex-pubs.csv"
openalex.publications_csv(
Expand Down

0 comments on commit 2dfbc57

Please sign in to comment.