diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index db80677f..18ccb942 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -122,7 +122,6 @@ class AbstractConnector(AbstractMinimalConnector): # load the json data = self.get_book_data(remote_id) - mapped_data = dict_from_mappings(data, self.book_mappings) if self.is_work_data(data): try: edition_data = self.get_edition_from_work_data(data) @@ -130,24 +129,26 @@ class AbstractConnector(AbstractMinimalConnector): # hack: re-use the work data as the edition data # this is why remote ids aren't necessarily unique edition_data = data - work_data = mapped_data + work_data = data else: edition_data = data try: work_data = self.get_work_from_edition_data(data) - work_data = dict_from_mappings(work_data, self.book_mappings) - except (KeyError, ConnectorException): - work_data = mapped_data + except (KeyError, ConnectorException) as e: + logger.exception(e) + work_data = data if not work_data or not edition_data: raise ConnectorException("Unable to load book data: %s" % remote_id) with transaction.atomic(): # create activitypub object - work_activity = activitypub.Work(**work_data) + work_activity = activitypub.Work( + **dict_from_mappings(work_data, self.book_mappings) + ) # this will dedupe automatically work = work_activity.to_model(model=models.Work) - for author in self.get_authors_from_data(data): + for author in self.get_authors_from_data(work_data): work.authors.add(author) edition = self.create_edition_from_data(work, edition_data) diff --git a/bookwyrm/connectors/inventaire.py b/bookwyrm/connectors/inventaire.py index c13ef7f8..60f490f3 100644 --- a/bookwyrm/connectors/inventaire.py +++ b/bookwyrm/connectors/inventaire.py @@ -137,9 +137,8 @@ class Connector(AbstractConnector): return self.get_book_data(self.get_remote_id(uri)) def get_work_from_edition_data(self, data): - try: - uri = data["claims"]["wdt:P629"] - except KeyError: + uri = data.get("wdt:P629", [None])[0] + if not uri: raise ConnectorException("Invalid book data") return self.get_book_data(self.get_remote_id(uri))