Fixes exception for openlibrary editions without works

This commit is contained in:
Mouse Reeve 2020-05-03 13:53:56 -07:00
parent d8934879e9
commit 93e12ac445

View file

@ -88,7 +88,13 @@ class Connector(AbstractConnector):
edition_data = self.load_book_data(olkey)
edition = self.create_book(olkey, edition_data, models.Edition)
work_key = edition_data.get('works')[0]['key'].split('/')[-1]
work_data = edition_data.get('works')
if not work_data:
# hack: we're re-using the edition data as the work data
work_key = olkey
else:
work_key = work_data[0]['key'].split('/')[-1]
work = models.Work.objects.filter(
openlibrary_key=work_key
).first()