Skip to content

Commit 747f68d

Browse files
Merge pull request #107 from NatLibFi/ekirjasto-18-show-failed-items-during-opds-import
Ekirjasto 18 show failed items during opds import
2 parents d8ab44f + bcf5372 commit 747f68d

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

core/opds_import.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,20 +1958,29 @@ def _get_feeds(self) -> Iterable[tuple[str, bytes]]:
19581958
return reversed(feeds)
19591959

19601960
def run_once(self, progress: TimestampData) -> TimestampData:
1961+
"""
1962+
Import all books in a feed.
1963+
1964+
:param progress: A TimestampData object indicating the start time of the run.
1965+
:return: A new TimestampData object with an achievements field
1966+
containing details of the operation.
1967+
"""
19611968
feeds = self._get_feeds()
19621969
total_imported = 0
19631970
total_failures = 0
1971+
failure_summary = []
19641972

19651973
for link, feed in feeds:
19661974
self.log.info("Importing next feed: %s", link)
19671975
imported_editions, failures = self.import_one_feed(feed)
19681976
total_imported += len(imported_editions)
19691977
total_failures += len(failures)
1978+
for failure_id, failure_details in failures.items():
1979+
failure_summary.append(f"ISBN: {failure_id}: {failure_details}")
19701980
self._db.commit()
1971-
1972-
achievements = "Items imported: %d. Failures: %d." % (
1973-
total_imported,
1974-
total_failures,
1981+
achievements = (
1982+
"Items imported: %d. Failures: %d.\nFailed IDs and details:\n%s"
1983+
% (total_imported, total_failures, "\n".join(failure_summary))
19751984
)
19761985

19771986
return TimestampData(achievements=achievements)

tests/core/test_opds_import.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,7 @@ def test_import_one_feed(self, opds_importer_fixture: OPDSImporterFixture):
19481948
collection=collection,
19491949
)
19501950
assert "Utter failure!" in failure.exception
1951-
1951+
print(failures)
19521952
# Both failures were reported in the return value from
19531953
# import_one_feed
19541954
assert 2 == len(failures)
@@ -1992,7 +1992,9 @@ def import_one_feed(self, feed):
19921992
assert ["last page", "second page", "first page"] == monitor.imports
19931993

19941994
# Every page of the import had two successes and one failure.
1995-
assert "Items imported: 6. Failures: 3." == progress.achievements
1995+
assert (
1996+
"Items imported: 6. Failures: 3.\nFailed IDs and details:\nISBN: identifier: Failure\nISBN: identifier: Failure\nISBN: identifier: Failure"
1997+
) == progress.achievements
19961998

19971999
# The TimestampData returned by run_once does not include any
19982000
# timing information; that's provided by run().

0 commit comments

Comments
 (0)