From 9ae0c1df95175b6abf5ade6ce63f30dea981d4fb Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Wed, 28 Jul 2021 12:32:04 +0100 Subject: [PATCH] Fix custom series indicies being preserved when a custom series is cleared, making the column sort correctly. The problem is that the series index is still in the table cache for a book after the series is removed. See https://www.mobileread.com/forums/showthread.php?p=4142361#post4142361 I freely confess that this might not be the best fix. :) --- src/calibre/db/write.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/calibre/db/write.py b/src/calibre/db/write.py index 222e88dafa..3cfcfe0884 100644 --- a/src/calibre/db/write.py +++ b/src/calibre/db/write.py @@ -239,7 +239,10 @@ def custom_series_index(book_id_val_map, db, field, *args): ids = series_field.ids_for_book(book_id) if ids: sequence.append((sidx, book_id, ids[0])) - field.table.book_col_map[book_id] = sidx + if series_field.table.book_col_map.get(book_id) is None: + field.table.book_col_map.pop(book_id, None) + else: + field.table.book_col_map[book_id] = sidx if sequence: db.executemany('UPDATE %s SET %s=? WHERE book=? AND value=?'%( field.metadata['table'], field.metadata['column']), sequence)