Skip to content

Deleting a book wipes shared text/enumeration custom column values from all books - #1669

Open
wheezer256 wants to merge 1 commit into
crocodilestick:mainfrom
wheezer256:fix-delete-shared-cc-values
Open

wheezer256 wants to merge 1 commit into
crocodilestick:mainfrom
wheezer256:fix-delete-shared-cc-values

Conversation

@wheezer256

Copy link
Copy Markdown

Bug

Deleting a single book from the web UI removes that book's value of any single-value text or enumeration custom column from every other book in the library.

In delete_whole_book(), the fallthrough else: branch for non-multiple custom columns does
calibre_db.session.delete(del_cc). For text and enumeration columns, del_cc is not a per-book row: it is the shared value row in custom_column_N, linked to books through books_custom_column_N_link. Deleting it orphans the link for every book that carried that value.

Reproduce

  1. Create an enumeration column, e.g. #topic with values Fantasy and Romance.
  2. Set #topic = Fantasy on books A, B and C.
  3. Delete book A from the web UI.
  4. Books B and C now have an empty #topic, and Fantasy is gone from custom_column_N.

We hit this on a real library. Three UI deletes cleared the category from 233 books. An earlier single delete cleared it from about 2000 books.

Fix

Apply the guard the rating branch already uses. A shared (normalized) value row is deleted only when no other book links to it. datetime and comments values are per-book rows, so they are still deleted as before.

if c.datatype in ('int', 'datetime', 'comments') or len(del_cc.books) == 0:
    calibre_db.session.delete(del_cc)

Verified

Ran with the patch applied in a live instance. Deleting one book with #topic = Historical Fiction from the UI removed only that book. The other 49 books kept the value.

(Note: 'int' is in the per-book tuple because db.py names that datatype 'int', while the numeric branch above checks 'integer', so integer columns reach this branch. Those rows have book, not books.)

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.

1 participant