-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
unbreak my books for deleted books #11027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug where the "My Books" reading log page would crash when books referenced in the reading log had been deleted. Instead of asserting that all reading log items exist in Solr, it now gracefully handles missing books by logging warnings.
Key changes:
- Replaces a hard assertion with a conditional check for missing books
- Adds logging to track which books are missing from Solr
- Prevents page crashes when deleted books are referenced in reading logs
openlibrary/core/bookshelves.py
Outdated
"see add_storage_items_for_redirects()" | ||
) | ||
if len(solr_docs) <= len(reading_log_keys): | ||
missing = set(w for w, e in reading_log_keys) - set([doc['key'] for doc in solr_docs]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use set comprehension instead of list comprehension wrapped in set(). Change set([doc['key'] for doc in solr_docs])
to {doc['key'] for doc in solr_docs}
for better performance.
missing = set(w for w, e in reading_log_keys) - set([doc['key'] for doc in solr_docs]) | |
missing = set(w for w, e in reading_log_keys) - {doc['key'] for doc in solr_docs} |
Copilot uses AI. Check for mistakes.
for more information, see https://pre-commit.ci
Co-authored-by: Copilot <[email protected]>
Closes #10970
Technical
My Books reading log pages breaks when books deleted; a deletion should probably cascade and remove related books from reading log table (similar to how we update redirects). In the interim, this solution should unbreak book pages by changing the
assertion
to anif
check.Testing
Tested on testing.
Screenshot
Stakeholders