openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Want-to-read list throws error in processing template

Open bitnapper opened this issue 4 months ago • 3 comments

Problem

The want-to-read page (https://openlibrary.org/people/bitnapper/books/want-to-read) throws the following error:

/openlibrary/openlibrary/templates/my_books/dropper.html: error in processing template: AttributeError: 'title' (falling back to default template)

Image

Reproducing the bug

  1. Go to https://openlibrary.org/people/USERNAME/books/want-to-read
  • Expected behavior: no error
  • Actual behavior: error above mentioned

Context

  • Browser firefox latest
  • OS (Windows, Mac, etc): linux
  • Logged in (Y/N): yes
  • Environment (prod, dev, local): prod

Breakdown

Implementation Details (for maintainers)

Requirements Checklist

  • [ ]

Related files

Stakeholders


Instructions for Contributors

  • Please run these commands to ensure your repository is up to date before creating a new branch to work on this issue and each time after pushing code to Github, because the pre-commit bot may add commits to your PRs upstream.

bitnapper avatar Jul 16 '26 05:07 bitnapper

hey, i dug into this and found the exact crash path.

root cause — add_storage_items_for_redirects in openlibrary/core/bookshelves.py (line 282) creates a bare stub for any reading log work that is missing from Solr and has no edition key:

solr_docs.append(web.storage({"key": key}))

this stub only has key — no title, no type, nothing else.

that stub flows into SearchResultsWork which classifies it as doc_type = 'solr_work' (no type.key, no editions) and, since it's your own reading log page, calls render_template('my_books/dropper', doc, ...). inside dropper.html line 29:

$ title = work.title if work else (edition.get('title', '') if edition else '')

work is truthy (non-empty web.storage) but work.title raises AttributeError: 'title' because web.storage.__getattr__ raises for missing keys. that's the exact error in the report.

conditions for the crash: viewing your own reading log, with at least one entry whose work has been redirected to another OL key and was added without a specific edition. those works don't come back from Solr, and add_storage_items_for_redirects inserts a title-less stub to keep the count right.

proposed fix — two places:

  1. bookshelves.py line 282 — include a title in the stub so the template doesn't blow up:

    solr_docs.append(web.storage({"key": key, "title": ""}))
    
  2. dropper.html line 29 — switch from attribute access to .get() for defense in depth (this is already how edition is handled on the same line):

    $ title = work.get('title', '') if work else (edition.get('title', '') if edition else '')
    

related: #13170 (blank entries) is a different but connected symptom — those entries come from add_storage_items_for_deletes (line 319-326) which does set title: "[Record deleted]" so it doesn't crash, but the stubs lack cover, author, keys etc. so they render as blank cards. worth addressing in the same PR.

happy to open a PR if this diagnosis looks right to maintainers.

TechGenius-Karan avatar Jul 18 '26 13:07 TechGenius-Karan

@TechGenius-Karan -- this seems like a reasonable hunch! If you'd like to open a PR, we can put it on testing and see if it resolves the problem. Ultimately deferring to @cdrini as the assigned issue lead on the decision whether to merge or if a different direction makes sense.

mekarpeles avatar Jul 20 '26 15:07 mekarpeles

Hi, thank you for assigning me to this issue. I will shortly link a PR following the approach I had mentioned earlier. We can then test it to see if it resolves the issue.

TechGenius-Karan avatar Jul 21 '26 07:07 TechGenius-Karan