This commit is contained in:
Kovid Goyal 2021-07-28 20:13:27 +05:30
commit 8b0ae7bde2
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 9 additions and 6 deletions

View File

@ -426,10 +426,7 @@ class WritingTest(BaseTest):
self.compare_metadata(nmi, oldmi, exclude={'last_modified', 'format_metadata', 'formats'})
cache.set_metadata(1, mi2, force_changes=True)
nmi2 = cache.get_metadata(1, get_cover=True, cover_as_data=True)
# The new code does not allow setting of #series_index to None, instead
# it is reset to 1.0
ae(nmi2.get_extra('#series'), 1.0)
self.compare_metadata(nmi2, oldmi2, exclude={'last_modified', 'format_metadata', '#series_index', 'formats'})
self.compare_metadata(nmi2, oldmi2, exclude={'last_modified', 'format_metadata', 'formats'})
cache = self.init_cache(self.cloned_library)
mi = cache.get_metadata(1)

View File

@ -233,13 +233,19 @@ def one_one_in_other(book_id_val_map, db, field, *args):
def custom_series_index(book_id_val_map, db, field, *args):
series_field = field.series_field
sequence = []
for book_id, sidx in iteritems(book_id_val_map):
for book_id, sidx in book_id_val_map.items():
if sidx is None:
sidx = 1.0
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
field.table.book_col_map[book_id] = sidx
else:
# the series has been deleted from the book, which means no row for
# it exists in the series table. The series_index value should be
# removed from the in-memory table as well, to ensure this book
# sorts the same as other books with no series.
field.table.remove_books((book_id,), db)
if sequence:
db.executemany('UPDATE %s SET %s=? WHERE book=? AND value=?'%(
field.metadata['table'], field.metadata['column']), sequence)