Skip to content

Commit cafee2c

Browse files
committed
fix: handle missing publisher fields in invenio_server_name()
`invenio_server_name(...)` tries to get the name of the server by getting the first record and looking in the field metadata.publisher in that record. It turns out our test server doesn't have a `publisher` field in that record, so the function failed. The new code falls back to using the host name as the server name if it can't get a `publisher` field value.
1 parent e213baa commit cafee2c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

iga/invenio.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ def invenio_server_name(server_url):
130130
log(f'we can reach {server_url} and it responds to {endpoint}')
131131
data = response.json()
132132
record = data.get('hits', {}).get('hits', {})[0]
133+
if publisher := record.get('metadata', {}).get('publisher'):
134+
return publisher
135+
else:
136+
# Fall back to the host name.
137+
return server_host
133138
return record['metadata']['publisher']
134139
except KeyboardInterrupt:
135140
raise

0 commit comments

Comments
 (0)