From 540b347fbaac841461b41f1cbeac5a821489b4f1 Mon Sep 17 00:00:00 2001 From: Daniel Bernstein Date: Fri, 22 Sep 2023 10:12:13 -0700 Subject: [PATCH] Prevent empty pointer problem. Improve logging to show detailed failure info in logs during OPDS feed imports. Resolves: https://ebce-lyrasis.atlassian.net/browse/PP-192 --- api/opds_for_distributors.py | 5 ++++- core/opds_import.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/api/opds_for_distributors.py b/api/opds_for_distributors.py index 421f4ec883..88d5f753f8 100644 --- a/api/opds_for_distributors.py +++ b/api/opds_for_distributors.py @@ -357,7 +357,10 @@ def update_work_for_edition(self, *args, **kwargs): pool, work = super().update_work_for_edition( *args, is_open_access=False, **kwargs ) - pool.unlimited_access = True + + if pool: + pool.unlimited_access = True + return pool, work @classmethod diff --git a/core/opds_import.py b/core/opds_import.py index 7fc4dc618b..6b52d77406 100644 --- a/core/opds_import.py +++ b/core/opds_import.py @@ -524,6 +524,12 @@ def import_from_feed(self, feed, feed_url=None): if work: works[key] = work except Exception as e: + logging.warning( + f"Non-fatal exception: Failed to import item - import will continue: " + f"identifier={key}; collection={self.collection.name}; " + f"data_source={self.data_source}; exception={e}", + stack_info=True, + ) identifier, ignore = Identifier.parse_urn(self._db, key) data_source = self.data_source failure = CoverageFailure(