Want-to-read list throws error in processing template
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)
Reproducing the bug
- 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.
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:
-
bookshelves.pyline 282 — include atitlein the stub so the template doesn't blow up:solr_docs.append(web.storage({"key": key, "title": ""})) -
dropper.htmlline 29 — switch from attribute access to.get()for defense in depth (this is already howeditionis 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 -- 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.
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.