Skip to content
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

Adds management command to repair editions in bad state #2905

Merged
merged 6 commits into from
Aug 2, 2023

Conversation

mouse-reeve
Copy link
Member

Sometimes editions are created without an associated parent work, which is Not Great, but difficult to ensure never happen. This command will match an orphan edition with a work, if there's another edition with the same unique identifiers (like ISBN), and create a new work if not. I've also added some logic to have this case fail gracefully in the UI to avoid server errors popping up all over the place.

I didn't have a chance to test this code before I had to go hang out with a cool baby so it needs more work, but should be the right idea

Fixes #2895

If an edition is missing its work, this change allows the page to still
load without a server error; this is important because otherwise the
book will break every page it appears on, including the feed page.
It's rare that it will be useful, and it was a huge hassle.
@mouse-reeve mouse-reeve marked this pull request as ready for review July 23, 2023 01:16
Copy link
Contributor

@axiomizer axiomizer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with the following steps:

  • build dev instance from main branch
  • update bookwyrm_edition set parent_work_id = NULL where isbn_13='9780553173253';
  • navigate to the book's page and it crashes
  • build dev instance from broken-editions branch
  • book's parent_work_id is still NULL
  • docker-compose run --rm web python manage.py repair_editions (fix typo in repair_editions.py)
  • the parent_work_id is set, and there's a new entry in bookwyrm_work and bookwyrm_book with that new id
  • navigate to the book's page and it doesn't crash now
  • docker-compose run --rm web python manage.py test bookwyrm.tests.models.test_book_model (10 tests passed)
  • docker-compose run --rm web python manage.py test bookwyrm.tests.templatetags.test_rating_tags (4 tests passed)

bookwyrm/models/book.py Outdated Show resolved Hide resolved
bookwyrm/models/book.py Show resolved Hide resolved
bookwyrm/management/commands/repair_editions.py Outdated Show resolved Hide resolved
@mouse-reeve
Copy link
Member Author

Extremely appreciate the review, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Book with no parent work causing server errors
2 participants