openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Want-to-read list hast 'blank entries'

Open bitnapper opened this issue 4 months ago • 3 comments

Problem

The want-to-read list has entries which don't show a cover, title, author or necessary buttons to remove them. But they link to the regarding work item which can be added a second time though and that new items appears on the list normally, the broken one stays though.

Image

Reproducing the bug

  1. Go to https://openlibrary.org/people/bitnapper/books/want-to-read
  2. find an entry which appears with no working buttons

Context

  • Browser (Chrome, Safari, Firefox, etc):
  • OS (Windows, Mac, etc):
  • Logged in (Y/N):
  • 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

Thank you @bitnapper for submitting this issue!

⚠️ Contributors, this issue will be ready to work on once:

  • [ ] Triage — maintainers will add Priority: * and Lead: @*
  • [ ] Needs: Breakdown — issue lacks concrete implementation steps

Context

This looks like the same underlying root cause as issue #13169 (opened by the same reporter, same day, also on the want-to-read shelf): both are almost certainly triggered by Bookshelves.add_storage_items_for_redirects:

https://github.com/internetarchive/openlibrary/blob/5aa48e60067402a069693c21dc0210b833b4f73d/openlibrary/core/bookshelves.py#L277-L282

When a reading-log entry's work has been merged/redirected and no edition_key was recorded for it, this code pushes a bare placeholder — web.storage({"key": key}) — into solr_docs, with no title, cover, or author data. That placeholder is what ends up on the shelf.

  • In reading_log.html → macros/SearchResultsWork.html, title is read defensively (doc.get('title', '-'), line 28), so the row just renders blank — no cover, title, or author, matching this issue's screenshot.
  • In my_books/dropper.html (line 29), title is read via direct attribute access (work.title), which raises AttributeError: 'title' on the same placeholder object — which is exactly the error reported in #13169. This is likely also why the remove/action buttons are missing here: dropper.html is what renders those, and when it errors, web.py falls back to an empty default template for that section.

A near-identical case (/type/delete records) was already fixed for exactly this reason in #11027 and again in add_storage_items_for_deletes (L310-L337), which gives deleted records a friendly [Record deleted] title stub. The redirect-with-no-edition branch never received the same treatment, and remains unchanged since it was introduced.

Also related (different subsystem, same class of bug): #10735 — Lists don't follow work redirects either, because list "seed" arrays live in Infobase rather than the SQL tables that resolve_redirect_chain already updates for reading logs, ratings, etc.

Issue Assessment

Open questions

  • Should the fix for the no-edition redirect case add a placeholder title (mirroring add_storage_items_for_deletes's [Record deleted]), or should it resolve the redirect target and re-fetch proper Solr data for the new work key?
  • [ ] Confirming that @bitnapper's specific affected entries are redirect-with-no-edition (vs. some other case) would require checking the reading_log DB in production — flagging in case a maintainer wants to verify before scoping the fix.

Suggested breakdown

  • [ ] Confirm root cause against production data: verify the affected want-to-read entries correspond to merged/redirected works with no edition_key, per Bookshelves.add_storage_items_for_redirects
  • [ ] Give the no-edition redirect placeholder a friendly title/cover fallback, mirroring add_storage_items_for_deletes's handling of /type/delete records
  • [ ] Harden my_books/dropper.html line 29 against a missing title attribute (e.g. work.get('title', ...) instead of work.title) — this alone could be a Good First Issue and would resolve #13169's error
  • [ ] Add a test covering redirected reading-log entries with no edition_key rendering safely in both the shelf listing and the dropper

🔔 Stakeholders

@cdrini — most recent/active contributor on openlibrary/core/bookshelves.py's redirect/delete stub handling (added the [Record deleted] stub fix), and already engaged as domain expert on the related redirect-propagation issue #10735.

Full triage checklist
  • [ ] Triage — correct labels applied or removed
  • [x] Problem / opportunity — problem is clear, audience identified, actionable
  • [x] Scope — issue is well-scoped; does not try to do too many things
  • [ ] Justification — reasoning and impact stated; sufficient for leads to prioritize
  • [ ] Success & testing criteria — defines what "done" looks like, verifiable by a contributor
  • [ ] Proposal & breakdown — concrete plan present; checklist actionable for a contributor
  • [ ] If bug: environment & repro steps — browser, version, local vs prod; steps to reproduce
  • [x] Risks, concerns, open questions — identified and surfaced
  • [x] Richy context — relevant code, commits, PRs reviewed; no duplicate found
  • [x] References — screenshots, designs, docs, and links present where needed

[!NOTE] This comment was automatically generated by Richy, Open Library's issue enrichment assistant, on behalf of @mekarpeles. This is NOT a sign-off. This issue needs lead review before work begins.

openlibrary-bot avatar Jul 16 '26 05:07 openlibrary-bot

Confirmed this on the reporter's shelf. The blank entry is /works/OL35659927W, which is a /type/redirect to /works/OL19859295W ("This is How You Lose the Time War"). The old key isn't in Solr (numFound 0), but the target is fully indexed (numFound 1, 14 editions, covers). Clicking the row already lands on the enriched work, so the data was always reachable, the shelf just wasn't following the hop.

On the open question (placeholder title vs resolve the target), I'd vote resolve-and-refetch. It's a small change to the no-edition branch that currently gives up: follow the redirect one hop and refetch the target from Solr by key, then render it under the key the reading log stored. Sketch:

target_to_originals: dict[str, list[str]] = {}
for doc in site.get().get_many(editionless_keys):
    if doc.type.key == "/type/redirect" and doc.location:
        target_to_originals.setdefault(doc.location, []).append(doc.key)
    elif doc.type.key == "/type/delete":
        solr_docs.append(web.storage({"key": doc.key, "title": _("[Record deleted]")}))
    else:
        solr_docs.append(web.storage({"key": doc.key, "title": ""}))

if target_to_originals:
    fq = "key:(%s)" % " OR ".join(f'"{t}"' for t in target_to_originals)
    resp = await run_solr_query_async(..., extra_params=[("fq", fq)])
    for doc in resp.docs:
        for original in target_to_originals.get(doc["key"], []):
            row = web.storage(doc)
            row["key"] = original
            solr_docs.append(row)

Have it working with tests passing. Happy to open a PR if that's the direction.

comaeclipse avatar Aug 03 '26 15:08 comaeclipse

I wouldn't limit it to a single redirect since I'm sure there are chains of redirects where works have been merged multiple times due to the poor quality of the metadata. A limit of 5 or 10 would be reasonable though to make sure you don't get caught in an infinite redirect loop.

tfmorris avatar Aug 03 '26 17:08 tfmorris