Skip to content

Commit

Permalink
Handle single DOI not found in OpenAlex
Browse files Browse the repository at this point in the history
  • Loading branch information
lwrubel committed Jul 9, 2024
1 parent 82286d1 commit fbfbb12
Show file tree
Hide file tree
Showing 2 changed files with 12 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 pubs:
yield normalize_publication(pubs[0])
except api.QueryError as e:
logging.error(f"OpenAlex QueryError for {doi}: {e}")
continue
Expand Down
10 changes: 10 additions & 0 deletions test/harvest/test_openalex.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ def test_publications_from_invalid_dois(caplog):
), "logs error message"


def test_publications_from_only_invalid_dois(caplog):
# Error may change if OpenAlex API or pyalex changes
invalid_dois = ["doi-with-comma,a", "another-invalid,doi"]
assert len(list(openalex.publications_from_dois(invalid_dois))) == 0
assert (
"OpenAlex QueryError for doi-with-comma,a: 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 fbfbb12

Please sign in to comment.