From 391f100e8de1ae56078d565aef8a1b3613c8411d Mon Sep 17 00:00:00 2001 From: MahdiiFakhfakh Date: Sun, 24 May 2026 15:31:45 +0100 Subject: [PATCH 1/2] Skip missing books in IA carousels --- openlibrary/plugins/openlibrary/home.py | 2 +- openlibrary/plugins/openlibrary/tests/test_home.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/openlibrary/plugins/openlibrary/home.py b/openlibrary/plugins/openlibrary/home.py index 4f93f5257c0..ab6a9860fe8 100644 --- a/openlibrary/plugins/openlibrary/home.py +++ b/openlibrary/plugins/openlibrary/home.py @@ -175,7 +175,7 @@ def get_ia_carousel_books( safe_mode=safe_mode, ) formatted_books = [ - format_book_data(book, False) for book in books if book != 'error' + format_book_data(book, False) for book in books if book and book != 'error' ] return formatted_books diff --git a/openlibrary/plugins/openlibrary/tests/test_home.py b/openlibrary/plugins/openlibrary/tests/test_home.py index 9abea238b8b..acc780abcf3 100644 --- a/openlibrary/plugins/openlibrary/tests/test_home.py +++ b/openlibrary/plugins/openlibrary/tests/test_home.py @@ -134,6 +134,15 @@ def spoofed_generic_carousel(*args, **kwargs): assert "About the Project" in html +class Test_get_ia_carousel_books: + def test_skips_missing_books(self, monkeypatch): + book = web.storage(key="/books/OL1M") + monkeypatch.setattr(home.lending, "get_available", lambda **kwargs: [book, None, "error"]) + monkeypatch.setattr(home, "format_book_data", lambda book, fetch_availability: {"key": book.key}) + + assert home.get_ia_carousel_books() == [{"key": "/books/OL1M"}] + + class Test_format_book_data: def test_all(self, mock_site, mock_ia): mock_site.quicksave("/books/OL1M", "/type/edition", title="Foo") From 0af6e22e9460f9c64898093fdf519931ec574aad Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 24 May 2026 14:38:33 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- openlibrary/plugins/openlibrary/home.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/openlibrary/plugins/openlibrary/home.py b/openlibrary/plugins/openlibrary/home.py index 4a50971a225..1bd833adbec 100644 --- a/openlibrary/plugins/openlibrary/home.py +++ b/openlibrary/plugins/openlibrary/home.py @@ -171,9 +171,7 @@ def get_ia_carousel_books(query=None, subject=None, sorts=None, limit=None, safe query=query, safe_mode=safe_mode, ) - formatted_books = [ - format_book_data(book, False) for book in books if book and book != 'error' - ] + formatted_books = [format_book_data(book, False) for book in books if book and book != "error"] return formatted_books